mysql遠程不能登入,問題就在於當時設置的賬號只限制本地訪問,MySQL默認也只是本地訪問。
之前的設置:
通過命令行登錄管理MySQL服務器(提示輸入密碼時直接回車):
mysql> /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/MySQL.sock
MySQL> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
MySQL> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
(1)可以把127.0.0.1改成你希望訪問的IP
(2)'%'怎表示任何IP都可以訪問。
1、修改表,登錄mysql數據庫,切換到MySQL數據庫,使用sql語句查看
2、授權用戶,你想root使用密碼從任何主機連接到MySQL服務器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin123' WITH GRANT OPTION;flush privileges;
如果你想允許用戶root從ip為192.168.12.16的主機連接到MySQL服務器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.16' IDENTIFIED BY '123456' WITH GRANT OPTION;
[root@localhost bin]# ./MySQL -uroot -p
Enter passWord:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9277
Server version: 5.5.3-m3-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL> GRANT ALL PRIVILEGES ON *.* TO'admin'@'%' IDENTIFIED BY 'Xinying_2010';
ERROR 2006 (HY000): MySQL Server has gone away
No connection. Trying to reconnect...
Connection id: 9324
Current database: *** NONE ***
Query OK, 0 rows affected (0.01 sec)
MySQL> flush privileges;
Query OK, 0 rows affected (0.00 sec)
注意:最後一句很重要,目的是使修改生效.如果沒有寫,則還是不能進行遠程連接.
現在就可以使用MySQL的客戶端軟件去連接你的數據庫了
我使用的是Navicat for MySQL