Linux 安装 MySQL 8 的错误整理(未完)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock '

这个问题发生在账户登录的时候,无论密码正确与否,始终出现2002错误。我的解决过程如下

直接删除临时文件夹下的4个文件(这4个文件权限是错的)

[root@instance-20mosyry ~]# rm /tmp/mysql*
rm: remove socket ‘/tmp/mysql.sock’? y
rm: remove regular file ‘/tmp/mysql.sock.lock’? y
rm: remove socket ‘/tmp/mysqlx.sock’? y
rm: remove regular file ‘/tmp/mysqlx.sock.lock’? y

然后重启mysql服务

[root@instance-20mosyry mysql]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service

再次查看临时文件夹,发现这4个文件又被创建了(因为是mysql自动创建的,权限已被自动纠正)。

[root@instance-20mosyry mysql]# ll /tmp
total 20
drwxr-xr-x 2 root  root  4096 Jun 19 22:41 bcm-agent
srwxrwxrwx 1 mysql mysql    0 Jun 24 14:36 mysql.sock
-rw------- 1 mysql mysql    5 Jun 24 14:36 mysql.sock.lock
srwxrwxrwx 1 mysql mysql    0 Jun 24 14:36 mysqlx.sock
-rw------- 1 mysql mysql    6 Jun 24 14:36 mysqlx.sock.lock
drwxr-xr-x 3 root  root  4096 Jun 20 11:05 pear
drwx------ 3 root  root  4096 Jun 24 14:33 systemd-private-a68349f1867e4285b26f8

再次使用root账户登录时2002错误已经不存在了。新的错误是密码错误,这个只要找到初始化数据库时的密码就可以了。

[root@instance-20mosyry mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
[root@instance-20mosyry mysql]#
[root@instance-20mosyry mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.16
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

输入显示数据库的命令报错1820,提示需要更改密码。

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo
mysql>
mysql> alter user root@localhost identified by 111111
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
mysql> alter user root@localhost identified by '111111';
Query OK, 0 rows affected (0.01 sec)

更改密码之后就可以正常操作了。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit;
Bye
讨论数量: 1

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

使用navicat连接的时候一切正常,但是浏览器访问却报错:authentication method unknown,此时只需编辑用户,将插件一栏的caching_sha2_password改成mysql_native_password就可以了。

file

3个月前 评论

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!