1. 登錄mysql
mysql -u root -p //輸入密碼
2. 使用命令show global variables like 'port';查看端口號
mysql> show global variables like 'port';
3. 修改端口,編輯/etc/my.cnf文件,早期版本有可能是my.conf文件名,增加端口參數,並且設定端口,注意該端口未被使用,保存退出。
[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
[root@test ~]# /etc/init.d/mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ]