欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySql修改默认端口的方法

程序员文章站 2022-03-02 22:21:20
1. 登录mysql [root@test /]# mysql -u root -p enter password: 2. 使用命令show global variables like 'p...

1. 登录mysql

[root@test /]# mysql -u root -p

enter password:

2. 使用命令show global variables like 'port';查看端口号

mysql> show global variables like 'port';

+---------------+-------+

| variable_name | value |

+---------------+-------+

| port | 3306 |

+---------------+-------+

1 row in set (0.00 sec)

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 ~]#systemctl restart mysqld

5.再次登录后检查端口已修改为’3506’.

[root@test etc]# mysql -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.66 source distribution

copyright (c) 2000, 2012, 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 global variables like 'port';

+---------------+-------+

| variable_name | value |

+---------------+-------+

| port | 3506 |

+---------------+-------+

1 row in set (0.00 sec)

mysql>

1. 登录mysql

[root@test /]# mysql -u root -p

enter password:

2. 使用命令show global variables like 'port';查看端口号

mysql> show global variables like 'port';

+---------------+-------+

| variable_name | value |

+---------------+-------+

| port | 3306 |

+---------------+-------+

1 row in set (0.00 sec)

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 ~]#systemctl restart mysqld

5.再次登录后检查端口已修改为’3506’.

[root@test etc]# mysql -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.66 source distribution

copyright (c) 2000, 2012, 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 global variables like 'port';

+---------------+-------+

| variable_name | value |

+---------------+-------+

| port | 3506 |

+---------------+-------+

1 row in set (0.00 sec)

mysql>