默认情况下Mysql的root用户不支持远程登录,使用以下命令授权
[Charles@localhost ~]$ mysql -uroot -p123
MariaDB [(none)]> use mysql;
MariaDB [mysql]> select Host from user;
+-----------+
| Host |
+-----------+
| 127.0.0.1 |
| ::1 |
| localhost |
+-----------+
3 rows in set (0.00 sec)
现在没有%,所以不能远程登录
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
MariaDB [mysql]> FLUSH PRIVILEGES;
MariaDB [mysql]> select Host from user;
+-----------+
| Host |
+-----------+
| % |
| 127.0.0.1 |
| ::1 |
| localhost |
+-----------+
4 rows in set (0.00 sec)