How to set the MySQL root password:
1, first install root initial password is empty, note is no password, directly hit enter
D:\wamp\bin\mysql\mysql5.6.17\bin>
mysql-uroot-p
Enter password: [Direct return]
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 7
Server version:5.6.17 MySQL Community Server (GPL)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
2. Several ways to change the root password:
1) Use Set password command
First log in to MySQL.
Format:mysql> set password for user name @localhost = password (' new password ');
For example:
Mysql>
Set password for [email protected] = password (' root ');
Query OK, 0 rows Affected (0.00 sec)
Mysql>
quit
Bye
D:\wamp\bin\mysql\mysql5.6.17\bin>
Mysql-uroot-proot
Warning:using a password on the command line interface can is insecure.
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 8
Server version:5.6.17 MySQL Community Server (GPL)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
2) Use Mysqladmin
Format: Mysqladmin-u username-P Old password password new password
For example:
D:\wamp\bin\mysql\mysql5.6.17\bin>
mysqladmin-uroot-proot Password root123
Warning:using a password on the command line interface can is insecure.
D:\wamp\bin\mysql\mysql5.6.17\bin>
mysql-uroot-proot123
Warning:using a password on the command line interface can is insecure.
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 10
Server version:5.6.17 MySQL Community Server (GPL)
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
3) Edit user table directly with update
First log in to MySQL.
mysql> use MySQL;
mysql> Update user Set Password=password (' root ') where user= ' root ' and host= ' localhost ';
mysql> flush Privileges;
--Attention must be flush privileges;
MySQL new setup user or change password after use flush privileges refresh the MySQL system permission related table, otherwise there will be denied access, there is another way, is to restart the MySQL server for the new settings to take effect.
4) When you forget the root password, you can do so.
Take windows as an example:
1. Close the running MySQL service.
2. Open the DOS window and go to the Mysql\bin directory.
3. Enter Mysqld--skip-grant-tables carriage return. --skip-grant-tables means skipping permission table authentication when starting the MySQL service.
4. Open a DOS window again (because the DOS window is no longer moving), go to the Mysql\bin directory.
5. Enter MySQL return and, if successful, the MySQL prompt > will appear.
6. Connection rights database: use MySQL;.
6. Change Password: Update user set Password=password (' root123 ') where user= ' root '; (don't forget the last semicolon).
7. Refresh permissions (required steps):
flush Privileges;
8. Exit the current CMD from quit and close the DOS window in 2
9. Using the username root, the new password root123 in the 4 DOS window login.
-----------------------------
Dylan presents.
How to set the MySQL root password