Linux 下第一次使用MySQL遇到几种情况
1.Access denied for user 'root'@'localhost' (using password: YES)~ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@tb1 lib]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@tb1 lib]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
这两种情况分别是输入密码和没输入密码造成的。为什么会输入密码和不输入密码都不会出错呢?那是因为你输入的密码不正确;有人会问,之前在装MySQL的时候不输入密码,直接enter键都能登录进去,现在为什么会报错呢?普及一下;在MySQL5.6之前的版本是不需要密码也可以登录的,在MySQL5.6以后就需要密码了,这也是解决问题的关键所在,那到底输入什么呢?
解决问提方法:
[root@tb1 /]# cat /var/log/mysqld.log
2017-07-23T06:53:34.320711Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-23T06:53:35.675810Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-23T06:53:35.983333Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-23T06:53:36.046408Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a652ec88-6f73-11e7-ae11-0800270a69b8.
2017-07-23T06:53:36.049362Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-07-23T06:53:36.050127Z 1 [Note] A temporary password is generated for root@localhost:s:..o!tQk9!D
最后标红的就是MySQL的初始密码;复制后粘贴,就可以正常进入MySQL了。
[root@tb1 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9
Copyright (c) 2000, 2015, 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>
2.mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement
翻译错误信息:在执行此操作之前,必须使用“用户声明”重新设置密码。
解决方法:重新设置密码。
mysql> SET PASSWORD = PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
下次登录就直接用刚才重置过的用户和密码登录。