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 © 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 © 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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL默认端口3306被占用可能是由于以下几个原因: 1. 另一个程序正在使用该端口:如果您在同一台计算机上安装了多个程序,可能会发生端口冲突。您可以使用网络工具(如netstat)来查看哪个程序正在使用3306端口,并尝试关闭或更改该程序的端口。 2. MySQL服务已经在运行:如果MySQL服务器已经在运行,它将占用默认端口。您可以尝试停止MySQL服务,然后再次启动它,以确保端口被正确释放。 3. 防火墙阻止了端口访问:某些防火墙设置可能会阻止对某些端口的访问,包括MySQL默认端口3306。您可以检查您的防火墙设置,确保它允许通过该端口进行通信。 解决这个问题的方法包括: 1. 更改MySQL默认端口:您可以通过修改MySQL配置文件(通常是my.cnf或my.ini)将默认端口更改为未被占用的端口号。 2. 停止占用3306端口的程序:如果另一个程序正在使用3306端口,您可以尝试停止它,以便MySQL可以使用该端口。您可以使用命令行或任务管理器来停止该程序。 3. 关闭防火墙或修改防火墙设置:如果防火墙阻止了对该端口的访问,您可以尝试关闭防火墙或修改防火墙设置,以允许MySQL通过该端口进行通信。 请注意,如果您对系统设置不太熟悉,更改端口或配置防火墙可能会对系统安全性产生影响。在做出任何更改之前,请确保您了解其潜在影响,并在必要时备份重要的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值