mysql 8里面使用global log_error_verbosity控制日志记录的详细程度:
Permitted Message Priorities log_error_verbosity Value
ERROR 1
ERROR, WARNING 2
ERROR, WARNING, INFORMATION 3
默认为2,设置为3,可以用于调试连接问题,这个参数可以联机设置:
mysql> set global log_error_verbosity=3; Query OK, 0 rows affected (0.00 sec)
设置为3后,错误日志里面有下面的信息:
2020-06-15T07:00:36.035923Z 50 [Note] [MY-010926] [Server] Access denied for user 'root'@'192.168.17.149' (using password: YES)
设置为2时,没有这个信息,这些信息对应的客户端的错误是:
scutech@scutech:~$ mysql -uroot -pdingjia -h192.168.17.40 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'192.168.17.149' (using password: YES)
使用下面的命令修改即可解决问题。
mysql> update mysql.user set host='%' where user='root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.02 sec)
如果错误日志里面没有这样的记录,那是根本没有连接过来,看看下面的例子:
scutech@scutech:~$ mysql --port 3360 --protocol tcp -uroot -pdingjia -hlocalhost mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)
端口写错了!