MySQL 8.0

1、修改密码

1
2
3
use mysql;
update user set authentication_string='' where user='root';
ALTER user 'root'@'%' IDENTIFIED BY 'yourPassword';

2、设置外部访问

1
2
use mysql;
update user set Host='%' where user='root';

问题

问题现象:

mysql> show databases;
ERROR 1449 (HY000): The user specified as a definer (‘mysql.infoschema‘@’localhost’) does not exist

解决方法:

1.先看下mysql是否设置了环境变量,如果没设置,就需要切换到mysql的bin目录下执行命令

1
mysql -P 3306 -h 127.0.0.1 -u root -p

2.给root用户添加权限

mysql8.0以前的版本可以使用grant在授权的时候隐式的创建用户,8.0以后已经不支持,所以必须先创建用户,然后再授权,命令如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
CREATE USER 'mysql.infoschema'@'localhost' IDENTIFIED BY '123456';




grant all privileges on *.* to 'mysql.infoschema'@'localhost';



flush privileges;







如果远程连接的时候报plugin caching_sha2_password could not be loaded这个错误,可以尝试修改密码加密插件:



alter user 'root'@'%' identified with mysql_native_password by '123456';