sudo apt install mysql-server
sudo mysql
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘123‘;
产生用户不能授权的原因是mysql 数据库中user 表中的特定用户(root) 的host 的属性值为localhost.
select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
解决办法如下:
mysql > use mysql;
mysql > update user set host=‘%‘ where user=‘root‘;
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ WITH GRANT OPTION;
flush privileges;
vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
port = 3306
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
原文:https://www.cnblogs.com/a208606/p/14228444.html