Linux開(kāi)啟mysql遠(yuǎn)程連接的設(shè)置步驟
MySQL默認(rèn)root用戶只能本地訪問(wèn),不能遠(yuǎn)程連接管理mysql數(shù)據(jù)庫(kù),Linux如何開(kāi)啟mysql遠(yuǎn)程連接?接下來(lái)是小編為大家收集的Linux開(kāi)啟mysql遠(yuǎn)程連接的設(shè)置步驟,歡迎大家閱讀:
Linux開(kāi)啟mysql遠(yuǎn)程連接的設(shè)置步驟
1、GRANT命令創(chuàng)建遠(yuǎn)程連接mysql授權(quán)用戶itlogger
mysql -u root -p
mysql>GRANT ALL PRIVILEGES ON *.* TO itlogger@localhost IDENTIFIED BY ‘www.itlogger.com’ WITH GRANT OPTION;
mysql>GRANT ALL PRIVILEGES ON *.* TO itlogger@”%” IDENTIFIED BY ‘www.itlogger.com’ WITH GRANT OPTION;
第一句增加itlogger用戶授權(quán)通過(guò)本地機(jī)(localhost)訪問(wèn),密碼“www.itlogger.com”。第二句則是授與itlogger用戶從任何其它主機(jī)發(fā)起的訪問(wèn)(通配符%)。
2、設(shè)置防火墻允許3306端口
vi /etc/sysconfig/IPtables
添加-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
(注意添加在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,否則可能導(dǎo)致規(guī)則不生效)
重啟防火墻service iptables restart
3、附:Mysql無(wú)法遠(yuǎn)程連接的常見(jiàn)問(wèn)題
1)查看Mysql的端口是否正確,通過(guò)netstat -ntlp查看端口占用情況,一般情況下端口是3306。
2)報(bào)錯(cuò):ERROR 2003 (HY000): Can’t connect to MySQL server on ’192.168.51.112′ (111)
查看/etc/my.cnf中,skip-networking 是否已被注掉,需要注掉。
3)報(bào)錯(cuò):ERROR 2003 (HY000): Can’t connect to MySQL server on ’192.168.51.112′ (113)
查看是否iptables沒(méi)有允許mysql連接,通過(guò):service iptables stop臨時(shí)關(guān)閉測(cè)試是否可以正常遠(yuǎn)程訪問(wèn),如果可以,按上面方面設(shè)置iptable允許3306端口
4)遠(yuǎn)程訪問(wèn)mysql速度很慢的解決方法
修改/etc/my.cnf或my.ini
[mysqld]下添加
skip-name-resolve
skip-grant-tables
**********************************************************************************************************************
mysql數(shù)據(jù)庫(kù)遠(yuǎn)程訪問(wèn)設(shè)置方法
1、修改localhost
更改 "mysql" 數(shù)據(jù)庫(kù)里的 "user" 表里的 "host" 項(xiàng),從"localhost"改成"%"
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>FLUSH PRIVILEGES;
2、指定授權(quán)
使用myuser/mypassword從任何主機(jī)連接到mysql服務(wù)器:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
使用myuser/mypassword從ip為192.168.225.166的主機(jī)連接到mysql服務(wù)器:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.225.166' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
3、泛授權(quán)
mysql -h localhost -u root
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; //賦予任何主機(jī)上以root身份訪問(wèn)數(shù)據(jù)的權(quán)限
mysql>FLUSH PRIVILEGES;
解決Mysql無(wú)法遠(yuǎn)程連接的問(wèn)題
1、Mysql的端口是否正確
通過(guò)netstat -ntlp查看端口占用情況,一般情況下端口是3306。在用工具連接MySQl是要用到端口。例如My Admin\My Query Browser\MySQl Front等。
2、檢查用戶權(quán)限是否正確
mysql庫(kù)的user表里有兩條記錄:host分別為localhost和%(為了安全,%可以換成你需要外部連接的IP)。
3、查看/etc/mysql/my.cnf中,skip-networking 是否已被注掉
需要注掉
報(bào)錯(cuò):ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.51.112' (111)
sudo gedit /etc/mysql/my.cnf
#skip-external-locking
#bind-address = 127.0.0.1
skip-name-resolve
4、查看iptables是否停掉,沒(méi)關(guān)的情況下,無(wú)法連接
通過(guò):service iptables stop臨時(shí)關(guān)閉。
報(bào)錯(cuò):ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.51.112' (113)
設(shè)置好以后需要重啟:sudo service mysql restart
看了“Linux開(kāi)啟mysql遠(yuǎn)程連接的設(shè)置步驟”還想看:
1.mysql怎么設(shè)置遠(yuǎn)程連接數(shù)據(jù)庫(kù)