1.问题描述
在ubuntu14.10终端下,执行命令:
$ mysql -uroot -p
并输入密码后进入mysql的shell, 然后在显示所有数据库时出现以下信息:
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
具体操作如下:
xx@ubuntu:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.5-m15
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> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql>
2.解决方法
以上信息提示比较明显,即在执行语句前必需设置密码,此处为了学习,故将密码设置为123456,且本人的root密码正是123456(密码请各位自行设置) ,操作如下:
mysql> SET PASSWORD = PASSWORD('123456');
执行完上面设置密码的命令后,问题即可解决。
以下为本人的操作:
xx@ubuntu:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.5-m15
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> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> use mysql;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.06 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql>
详情可以查询数据库mysql下的user表
mysql> select * from mysql.user;
或:
mysql> select host, user, password from mysql.user;