1. 程式人生 > >ubuntu下mysql不能用IP地址訪問的問題解決

ubuntu下mysql不能用IP地址訪問的問題解決

1.mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';

   (%) 表示所有ip

    第1個root表示賬戶

    第2個root表示密碼

2.mysql>flush privileges;

3.停止並重啟mysql服務。

停止命令:service mysql stop

啟動命令:service mysql start

檢視狀態:service mysql status

如果以上操作還是不能訪問,那麼應該是mysql沒有允許遠端訪問。

修改配置檔案:

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

將bind-address = 127.0.0.1註釋掉(即在行首加#),如下:

程式碼如下:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address          = 127.0.0.1然後重啟服務即可訪問了。