centos mysql 访问_centos下mysql开启远程访问
登錄MySQL:? mysql -u root -p;
然后輸入密碼,
如需修改密碼,第一次:? mysqladmin -u root password NEWPASSWORD
已設置過:? mysqladmin -u root -p 'oldpassword' password newpassword
執行以下命令開啟遠程訪問限制? grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
flush privileges;
exit;
上面的是開啟的IP 192.168.0.1的,如要開啟所有的,用%代替IP
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
CentOS,以下的命令在debian等系統下應該也OK。
mysql?-u root?-p mysql?# 第1個mysql是執行命令,第2個mysql是系統數據名稱
在mysql控制臺執行:
grant all privileges on?*.*to?'root'@'%'identified?by'123456'withgrant option;
# root是用戶名,%代表任意主機,'123456'指定的登錄密碼(這個和本地的root密碼可以設置不同的,互不影響)
flush privileges;# 重載系統權限
exit;
允許3306端口
iptables?-I INPUT?-p tcp?-m state?--state NEW?-m tcp?--dport?3306-j ACCEPT
# 查看規則是否生效
iptables?-L?-n?# 或者: service iptables status
# 此時生產環境是不安全的,遠程管理之后應該關閉端口,刪除之前添加的規則
iptables?-D INPUT?-p tcp?-m state?--state NEW?-m tcp?--dport?3306-j ACCEPT
PS,上面iptables添加/刪除規則都是臨時的,如果需要重啟后也生效,需要保存修改: service iptables save # 或者: /etc/init.d/iptables save 另外, vi /etc/sysconfig/iptables # 加上下面這行規則也是可以的 -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
總結
以上是生活随笔為你收集整理的centos mysql 访问_centos下mysql开启远程访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql安装ssl证书_Mysql配置
- 下一篇: mysql错误代码1813_ERROR