全程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.pid
service 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/