前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySql修改默认端口的操作方法

MySql修改默认端口的操作方法

原创
作者头像
用户1685462
修改2021-08-05 14:11:55
3.4K0
修改2021-08-05 14:11:55
举报
文章被收录于专栏:网站教程

1. 登录mysql  

代码语言:javascript
复制

[root@test /]# mysql -u root -p  
Enter password:  

2. 使用命令show global variables like 'port';查看端口号  
代码语言:javascript
复制

mysql> show global variables like 'port';  
+---------------+-------+  
| Variable_name | Value |  
+---------------+-------+  
| port | 3306 |  
+---------------+-------+  
1 row in set (0.00 sec)  

3. 修改端口,

编辑/etc/my.cnf文件,早期版本有可能是my.conf文件名,增加端口参数,并且设定端口,注意该端口未被使用,保存退出。  

代码语言:javascript
复制

[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  
代码语言:javascript
复制

 
[root@test ~]# systemctl restart mysqld

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

代码语言:javascript
复制

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2. 使用命令show global variables like 'port';查看端口号  
  • 3. 修改端口,
  • 4. 重新启动mysql  
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档