1. 登录mysql
1
2
|
mysql -u root -p //输入密码 |
2. 使用命令show global variables like 'port';查看端口号
1
|
mysql> show global variables like 'port' ; |
3. 修改端口
编辑/etc/my.cnf文件,早期版本有可能是my.conf文件名,增加端口参数,并且设定端口,注意该端口未被使用,保存退出。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@test etc] # vi my.cnf [mysqld] port=3506 datadir=/ var /lib/mysql socket=/ var /lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/ var /log/mysqld.log pid-file=/ var /run/mysqld/mysqld.pid "my.cnf" 11L, 261C written [root@test etc] # |
4. 重启mysql
1
2
3
|
[root@test ~] # /etc/init.d/mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ] |