backup1-technicise / Django-Sample

Few projects and CRUD operations using Django (1.11.2), Django Piston and Python 2.7
MIT License
1 stars 0 forks source link

steps to MySQL 5.6 installation and change password for MySQL root user with localhost domain #5

Open backup1-technicise opened 7 years ago

backup1-technicise commented 7 years ago

MySQL 5.6 installation

user@user-VirtualBox:~$ sudo apt-get install mysql-server-5.6

MySQL root password

curatehealth

Run MySQL

user@user-VirtualBox:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.6.33-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database employee_DB;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| employee_DB        |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit;
bye

Create table EMP_INFO under employee_DB

mysql> CREATE TABLE EMP_INFO (emp_ID VARCHAR(10),emp_name VARCHAR(40),emp_age INT,emp_sex VARCHAR(1),PRIMARY KEY(emp_ID));
Query OK, 0 rows affected (0.05 sec)

mysql> show tables;
+----------------------------+
| Tables_in_employee_DB      |
+----------------------------+
| EMP_INFO                   |
| auth_group                 |
| auth_group_permissions     |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_content_type        |
| django_migrations          |
| django_session             |
+----------------------------+
10 rows in set (0.00 sec)

mysql> 

Insert values into table EMP_INFO

mysql> describe EMP_INFO;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| emp_ID   | varchar(10) | NO   | PRI |         |       |
| emp_name | varchar(40) | YES  |     | NULL    |       |
| emp_age  | int(11)     | YES  |     | NULL    |       |
| emp_sex  | varchar(1)  | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.06 sec)

mysql> INSERT INTO EMP_INFO(emp_ID,emp_name,emp_age,emp_sex)VALUES("E1","Abhisek Roy",32,"M");
Query OK, 1 row affected (0.09 sec)

mysql> describe EMP_INFO;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| emp_ID   | varchar(10) | NO   | PRI |         |       |
| emp_name | varchar(40) | YES  |     | NULL    |       |
| emp_age  | int(11)     | YES  |     | NULL    |       |
| emp_sex  | varchar(1)  | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> select * from EMP_INFO;
+--------+-------------+---------+---------+
| emp_ID | emp_name    | emp_age | emp_sex |
+--------+-------------+---------+---------+
| E1     | Abhisek Roy |      32 | M       |
+--------+-------------+---------+---------+
1 row in set (0.03 sec)

mysql> 
backup1-technicise commented 7 years ago

How to change password for MySQL

The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:

    1. sudo vim /etc/mysql/my.cnf

    2. Add the following lines at the end:

    [mysqld]

    skip-grant-tables

    3. sudo service mysql restart

    4. mysql -u root

    5. UPDATE mysql.user set password = PASSWORD('your_new_password') where user = 'root' and host = 'localhost';

    6. exit

    7. Remove the lines added in step 2 if you want to keep your security standards.

    8. 4. mysql -u root -p