参考:
How to grant all privileges to root user in MySQL 8.0 - Stack Overflow
操作:
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD'(PASSWORD要改成你想要设置的密码,我之前没改,导致连接不上);
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
可以通过“select user, host, authentication_string from mysql.user;”查看设置是否成功
一般无需额外操作,如果不行,请参考下面检查bind-address = 127.0.0.1是否被注释(前面加了#)
linux - Can't connect to MySQL server error 111 - Stack Overflow
该配置文件可以通过“grep -R 'bind-address' /etc/mysql/* /ect/my.cnf”查看该配置在哪,下图可以看到时正常开启的,就不用管了