您好,登錄后才能下訂單哦!
實(shí)驗(yàn)環(huán)境:
操作系統(tǒng):Redhat 6.4
IP:10.1.1.99(虛擬機(jī))
數(shù)據(jù)庫(kù):MYSQL5.1
在Linux上安裝好MYSQL之后,進(jìn)行本地登錄
[root@wjq2 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
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>
登陸成功;
下面通過SQLyog客戶端來遠(yuǎn)程連接MYSQL服務(wù)器所遇問題進(jìn)行分析:
問題一:
問題分析:
[root@wjq2 ~]# service mysqld status
mysqld (pid 2364) is running...
[root@wjq2 ~]# netstat -nalp | grep "3306"
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2364/mysqld
tcp 0 0 10.1.1.99:3306 10.1.1.123:55569 ESTABLISHED 2364/mysqld
tcp 0 0 10.1.1.99:3306 10.1.1.123:55568 ESTABLISHED 2364/mysqld
本地用戶可以用3306端口連接,說明網(wǎng)絡(luò)沒有問題,3306端口也開啟著,其實(shí)問題可能出在iptables,查看iptables的運(yùn)行狀態(tài)
[root@wjq2 ~]# service iptables status
iptables: Firewall is not running.
發(fā)現(xiàn)iptables是禁用狀態(tài),所以問題并不是出現(xiàn)在iptables這里。
注意:
1、如果你的iptables沒有禁用,可以禁用iptables;
2、如果不想禁用iptables也可以,把-A INPUT -m state --state NEW -m tcp -p tcp --dport
3306 -j ACCEPT添加到/etc/sysconfig/iptables即可,表示允許3306端口通過防火墻。
[root@wjq2 ~]# cat
/etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A
RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
COMMIT
修改完之后,需要重新啟動(dòng)iptables方可生效
禁用iptables或修改完配置文件之后,再次遠(yuǎn)程連接MYSQL,又出現(xiàn)如下的錯(cuò)誤:
問題二:
問題分析:
根據(jù)錯(cuò)誤提示,10.1.1.123是我本地主機(jī)的網(wǎng)卡IP,遠(yuǎn)程連接時(shí)不允許通過該主機(jī)連接到MYSQL服務(wù)器;可以初步判斷可能是應(yīng)為缺少權(quán)限;
下面我將允許用戶root使用密碼XXX從任何主機(jī)連接到MYSQL服務(wù)器
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'XXX' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
或者是允許用戶root從IP為10.1.1.123的主機(jī)連接到MYSQL服務(wù)器,并使用XXX作為登錄密碼
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.1.1.123' IDENTIFIED BY 'XXX' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
授權(quán)成功之后,再次嘗試進(jìn)行遠(yuǎn)程連接,可以發(fā)現(xiàn)連接成功;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。