use mysql; # 刷新权限 flush privileges; # 添加用户 ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '密码'; # 刷新权限 flush privileges; quit; # 重启mysql service mysql restart
配置外网navicat可访问mysql
mysql -u root -p
use mysql; update user set host='%'where user='root' and host='localhost'; flush privileges;
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf # 在bin-address = 127.0.0.1前添加#号