支持外网访问的CentOS云数据库搭建
全程root權限下操作
華為云主機環境(云主機ip為:xx.xxx.xx.xx):
Linux CentOS6 2.6.32-696.16.1.el6.x86_64?
云主機mysql版本:
Server version: 5.1.73 Source distriution
首先確保使用的端口9999在云主機的控制臺(工程師對于控制臺不一定有操作權限,必須是購買云主機的人才有操作權限)上已經被打開,否則下面操作無效。
好,接下來開始改配置
vim /etc/my.cnf
[mysqld] #修改為你想要改的端口 port=9999 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log pid-file=/var/run/mYsqld/mysqld.pidservice mysqld restart
在云主機的終端下檢查下有效果:
[root@SI235ODF23J234IO etc]# netstat -antp |grep 9999
tcp? ? ? ? 0? ? ? 0 0.0.0.0:9999? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? ? ? ?LISTEN? ? ? 17612/mysqld? ? ? ??
tcp? ? ? ? 0? ? ? 0 xx.yy.zz.aa:9999? ? ? ? ? ?zz.zz.z.xxx:9114? ? ? ? ? ? ESTABLISHED 17612/mysqld? ? ? ??
在云主機的數據庫中檢查下有如下效果:
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port? ? ? ? ? | 9999? |
+---------------+-------+
1 row in set (0.00 sec)
以上所有步驟都是云主機上操作,下滿是自己筆記本操作
接下來是最終結果驗證:
下面在自己筆記本上連接云主機:
(python2.7) appleyuchi@ubuntu:~$ mysql -h xx.xxx.xx.xx(這里填寫要連接的云主機的ip) -P 9999(必須與上面云主機開放的端口一致) -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.73 Source distribution
Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database? ? ? ? ? ?|
+--------------------+
| information_schema |
| mysql? ? ? ? ? ? ? |
| test_appleyuchi? ? ?|
+--------------------+
3 rows in set (0.20 sec)
非常重要的參考文獻:
http://blog.itpub.net/26148431/viewspace-1466379/
總結
以上是生活随笔為你收集整理的支持外网访问的CentOS云数据库搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS下面ERROR 2002 (
- 下一篇: mysql某个字段改为非unique