1、在/etc/mysql/mysql.conf.d/mysql.cnf中找到bind-address = 127.0.0.1,将其改成bind-address = 0.0.0.0。ubuntu默认只允许本地访问mysql,这是因为mysql的bind-address=127.0.0.1,要支持远程连接的话需要把bind-address改成0.0.0.0.
2、重启数据库 service mysql restart
2、连接mysql时报错:message from server: "Host ‘192.168.76.89’ is not allowed to connect to this MySQL server
2、执行:select host from user where user = ‘root’; 发现, host的值就是localhost。
将它的值改掉:update user host=’%’ where user = ‘root’;
3、修改完成后,执行:flush privileges;
将修改内容生效,再次配置时,用IP地址或者localhost就能够正常连接到MySQL数据库了。
其操作如下:
mysql>use mysql
Reading table information for completion oftableandcolumn names
You can turn off this feature to get a quicker startup with-A
Database changed
mysql>select host fromuserwhereuser='root';+-----------+| host |+-----------+| localhost |+-----------+1rowinset(0.00 sec)
mysql>updateuserset host='%'whereuser='root';
Query OK,1row affected (0.00 sec)Rowsmatched: 1 Changed: 1Warnings: 0
mysql>select host fromuserwhereuser='root';+------+| host |+------+|%|+------+1rowinset(0.00 sec)
mysql> flush privileges;
Query OK,0rows affected (0.00 sec)