记一次MySQL8.0远程连接失败问题

部署MySQL

wget https://dev.mysql.com/get/mysql-apt-config_0.8.1-1_all.deb

dpkg -i mysql-apt-config_0.8.1-1_all.deb

安装:

Sudo apt-get install mysql-server -y

重启:

Sudo service mysql restart

创建新用户:这里的密码是踩坑之一

mysql>create user 'user'@'127.0.0.1' identified by '*passwd';

授权:

mysql>grant all on *.* to 'user'@'127.0.0.1';	本地授权
mysql>grant all on *.* to 'user'@'远程IP';	远程授权

刷新:

mysql>flush privileges;

问题记录

1:创建用户的时候密码不能以特殊字符开头,现在需要更改密码
MySQL8.0更改密码,注意 这两条命令已经不起作用了

mysql>update mysql.user set password='newpassword' where user='root';

 和

mysql>update mysql.user set password=PASSWORD('newpassword') where User='root';

现在的版本用的是:

mysql>alter user 'user'@'127.0.0.1' identified by 'passwd';

2:更改完密码之后远程连接连不上了
2.1更改完密码的用户需要重新授权

授权:
mysql>grant all on *.* to 'user'@'127.0.0.1';	本地授权
mysql>grant all on *.* to 'user'@'远程IP';	远程授权

远程连接还是不行
MySQL8.0有个插件是:mysql_native_password
所以这样操作

mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

重新授权
mysql>grant all on *.* to 'user'@'127.0.0.1';	本地授权
mysql>grant all on *.* to 'user'@'远程IP';	远程授权

刷新
flush privileges;

查看一下用户,主机和插件

在这里插入图片描述

远程连接成功