一般我们默认mysql使用端口3306,那如果想要修改端口如何操作呢?这里介绍两种方法,大家根据自己的实际情况进行选择。

宝塔面板中修改

对于安装了宝塔面板的人来说修改就太简单了。只需要简单的两步就好了。

步骤1:配置修改

步骤2:重载配置文件后启动

步骤3: 检查

mysql> show global variables like 'port';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1
Current database: *** NONE ***+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3305  |
+---------------+-------+
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>

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>

MySQL修改默认端口3306相关推荐

  1. centos mysql 端口_Linux CentOS Mysql修改默认端口

    为了提高服务器的安全性,本节课主要讲的是Linux下如何修改Mysql端口.支持Linux环境下大部分系统的修改,如Centos和Ubuntu等. 演示环境: Linux CentOS 6.3 X32 ...

  2. linux 修改mysql默认端口3306

    linux 修改mysql默认端口3306 cd /etc/mysql/my.cnf 修改两处 客户端的port=3306 和mysqld的服务器端口port=3306 [client] port=3 ...

  3. linux mysql端口启动失败怎么办,Linux下apache mysql等服务修改默认端口后无法正常启动解决办法...

    Linux下apache mysql等服务修改默认端口后无法正常启动解决办法 linux下 apache 等服务修改默认端口后无法正常启动解决办法 服务器上装了两个webserver,一个是nginx ...

  4. linux修改mysql的默认端口

    本文是基于centos7的环境进行编写,如果是其他linux系统命令可能不一样 1.首先我们查看mysql的默认端口 我们登录mysql到mysql查看mysql使用的端口 show global v ...

  5. CentOS Tomcat6 修改默认端口8080为80

    CentOS Tomcat6 修改默认端口8080为80 By 14 | Published 2012/11/07 修改tomcat的端口,在conf目录里的server.xml文件 1 <Co ...

  6. 如何在Spring boot中修改默认端口

    文章目录 介绍 使用Property文件 在程序中指定 使用命令行参数 值生效的顺序 如何在Spring boot中修改默认端口 介绍 Spring boot为应用程序提供了很多属性的默认值.但是有时 ...

  7. hexo修改默认端口

    hexo修改默认端口 默认使用4000端口,用hexo s -p 80 ,可以暂时修改启动端口. 但是每次启动都要写"-p 80"才行,过于繁琐. 修改方法: 找到node_mod ...

  8. Linux部署Tomcat踩的坑以及解决方案【8080无法访问、日志显示XX端口被占用、修改默认端口、无法提供安全连接】

    Linux部署Tomcat踩的坑以及解决方案[8080无法访问.日志显示XX端口被占用.修改默认端口.无法提供安全连接] 8080无法访问 解压开压缩包后,执行bin目录下的 startup.sh 后 ...

  9. Jetty修改默认端口

    Jetty修改默认端口 本机上8080端口被占用了,而jetty的默认端口就是8080 打开\jetty-9.3.13.M0\jetty-distribution-9.3.13.M0下的start.i ...

  10. centos8系统influxdb2修改默认端口8086

    centos8系统influxdb2修改默认端口8086 1.修改配置文件/etc/influxdb/config.toml 添加修改,把8086默认端口修改为8099 http-bind-addre ...

最新文章

  1. ANSI编码和标准代码页(code page)
  2. vs2017中编译提示一些系统头文件没有找到
  3. 帮你理清 SpringBoot 与 SpringMVC 的关系
  4. lazada选品怎么做,东南亚母婴玩具类目选品分析
  5. 新中大oracle实列名,新中大财务软件操作流程(完整版)
  6. ArrayList的容量
  7. JavaScript从入门到放弃 -(六)正则表达式
  8. springboot 事务嵌套问题_在springboot中写单元测试解决依赖注入和执行后事务回滚问题...
  9. 三十岁还没做到管理层的人,后来都怎么样了?
  10. 切换Pycharm的Python版本
  11. Xilinx ISE14.2新手入门
  12. 【每天一个 Linux 命令】tree命令
  13. Adapter模式简述
  14. 物体识别基本原理及其Python实现
  15. web前端html怎么求最大值和最小值,求js数组的最大值和最小值的四种方法
  16. NFT国内化的“数字藏品” 国内互联网龙头的入局
  17. Slax本地化:U盘上的Linux中文套件
  18. Node.js:npm install时出错 check python checking for Python executable “python2“ in the PATH
  19. 因为是程序员,被亲戚鄙视了!
  20. leetcode 546. Remove Boxes

热门文章

  1. 人工智能在电力系统中的应用前景怎么样
  2. 解决tkinter卡死问题
  3. 微信开发之JSSDK权限配置,服务器端获取签名等参数(java实现)
  4. eXeScope之类的程序资源修改器的使用,很牛!
  5. CMOS工作原理和概念
  6. v9更新系统后为何显示服务器连接,红伞V9升级不能……报告里说好多文件无法与服务器建立连接……...
  7. java p2p编程_JXTA-JAVA P2P网络编程技术(入门篇)
  8. OpenProcess()函数
  9. springboot学生在线考试管理系统
  10. Java菜鸟教程 for循环和while循环