MySQL初始化root密码

MySql初始化root密码

C:\Users\Lenovo>mysql -u root -p
Enter password:

不需要密码直接进入数据库。。


执行以下命令:

mysql> use mysql
Database changed
mysql> update user set password = password('034039') where host = 'localhost' and user = 'root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

初始化密码完成

使用新的密码登陆mysql。

C:\Users\Lenovo>mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

C:\Users\Lenovo>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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>

====END====

你可能感兴趣的:(MySQL初始化root密码)