1. 程式人生 > >linux下mysql允許遠端連線

linux下mysql允許遠端連線

1.檢視linux防火牆是否開放3306埠

執行iptables -nL --line-number
這裡寫圖片描述
這裡顯示DROP代表防火牆阻止了3306埠。

2.新增防火牆例外

執行vim /etc/sysconfig/iptables
這裡寫圖片描述

3.重啟防火牆

執行service iptables restart
檢視是否變為ACCEPT

4.建立遠端連線使用者並授權

mysql> select Host,User,Password from mysql.user;
+----------------+------------------+-------------------------------------------+
| Host | User | Password | +----------------+------------------+-------------------------------------------+ | localhost | root | *836E233974EBE6EA32F95F890A91363F8427F78B | | iz94926clkiz | root | *836E233974EBE6EA32F95F890A91363F8427F78B | | 127.0.0.1 | root | *836E233974EBE6EA32F95F890A91363F8427F78B | | ::1 | root | *
836E233974EBE6EA32F95F890A91363F8427F78B | | localhost | debian-sys-maint | *1460ED3535ABDBB887F9E5F57F40A2354610CDF3 | +----------------+------------------+-------------------------------------------+ rows in set (0.00 sec)

建立使用者

create user test identified by '123456';
+----------------+------------------+-------------------------------------------+
| Host | User | Password | +----------------+------------------+-------------------------------------------+ | localhost | root | *836E283974EBE6EA32F95F890A91363F8427F78B | | iz949s6clkiz | root | *836E283974EBE6EA32F95F890A91363F8427F78B | | 127.0.0.1 | root | *836E283974EBE6EA32F95F890A91363F8427F78B | | ::1 | root | *836E283974EBE6EA32F95F890A91363F8427F78B | | localhost | debian-sys-maint | *1460ED35E5ABDBB887F9E5F57F40A2354610CDF3 | | % | test | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +----------------+------------------+-------------------------------------------+ rows in set (0.00 sec)

授權

grant all privileges on *.* to 'test'@'%'identified by '123456' with grant option;
flush privileges;

修改使用者密碼

update mysql.user set password=password('新密碼') where User="test" and Host="localhost";

刪除使用者

delete from user where User='test' and Host='localhost';