MySQL错误1045(28000):对用户的“root”拒绝访问

解决方案:

上面的MySQL错误消息是MySQL Server禁止root用户远程连接的默认行为,如默认情况下,允许从localhost中的root用户连接到MySQL Server,即为“127.0.0.1”。
解决方案是创建一个新的管理员用户。
下面的SQL命令将创建名为“admin”和“授予远程访问的新用户:

mysql> CREATE USER 'admin'@'%' IDENTIFIED BY '';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

替代但不建议的解决方案是授予远程MySQL访问root用户:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

上面的命令将给root用户授予root用户远程连接的权限:

$ mysql -u root -ppassword -h 172.17.0.14
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.5.43-0+deb8u1 (Debian)
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> Bye

问题

无法远程访问MySQL数据库使用“root帐户”。
任何访问MySQL数据库的尝试都会导致错误:

ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
日期:2020-07-07 20:54:48 来源:oir作者:oir