Linux系統MySQL資料庫遠程設定
1.啟動服務和登陸
[root@localhost ~]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2.授權一個可以遠程登陸的使用者
mysql> grant all privileges on *.* to tong@'%' identified by 'system'; --建立一個遠端使用者
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; --更新許可權
Query OK, 0 rows affected (0.00 sec)
mysql>
3.關閉防火牆
[root@localhost ~]# /etc/init.d/iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost ~]#
4.用用戶端工具可以登陸了
C:\Users\Administrator>mysql -h 遠程IP -u tong -p --tong是遠端使用者名
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 5.5.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
錯誤處理:
(1)防火牆沒有關閉或防火牆沒有過濾3306連接埠
圖:
解決方案:
[root@localhost ~]# /etc/init.d/iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost ~]#
或者:
[root@localhost ~]# vim /etc/sysconfig/iptables --添加以下一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
(2)密碼輸入錯誤
圖:
解決方案:輸入正確的密碼,如果密碼忘記了在伺服器系統裡修改一下
Linux 下MySQL的安裝和遠程設定