Linux环境下修改MySQL端口方法

 

  1. 如何查看mysql 默认端口号和修改端口号 2015-03-19 17:42:18
  2.  
     
  3.  
     
  4.  
    1. 登录mysql
  5.  
     
  6.  
    [root@test /]# mysql -u root -p
  7.  
    Enter password:
  8.  
     
  9.  
     
  10.  
    2. 使用命令show global variables like 'port';查看端口号
  11.  
     
  12.  
    mysql> show global variables like 'port';
  13.  
    +---------------+-------+
  14.  
    | Variable_name | Value |
  15.  
    +---------------+-------+
  16.  
    | port | 3306 |
  17.  
    +---------------+-------+
  18.  
    1 row in set (0.00 sec)
  19.  
     
  20.  
     
  21.  
    3. 修改端口,编辑/etc/my.cnf文件,早期版本有可能是my.conf文件名,增加端口参数,并且设定端口,注意该端口未被使用,保存退出。
  22.  
     
  23.  
    [root@test etc]# vi my.cnf
  24.  
    [mysqld]
  25.  
    port=3506
  26.  
    datadir=/var/lib/mysql
  27.  
    socket=/var/lib/mysql/mysql.sock
  28.  
    user=mysql
  29.  
    # Disabling symbolic-links is recommended to prevent assorted security risks
  30.  
    symbolic-links=0
  31.  
     
  32.  
    [mysqld_safe]
  33.  
    log-error=/var/log/mysqld.log
  34.  
    pid-file=/var/run/mysqld/mysqld.pid
  35.  
     
  36.  
    "my.cnf" 11L, 261C written
  37.  
    [root@test etc]#
  38.  
     
  39.  
    4. 重新启动mysql
  40.  
     
  41.  
    [root@test ~]# /etc/init.d/mysqld restart
  42.  
    Stopping mysqld: [ OK ]
  43.  
    Starting mysqld: [ OK ]
  44.  
     
  45.  
    5.再次登录后检查端口已修改为’3506’.
  46.  
     
  47.  
    [root@test etc]# mysql -u root -p
  48.  
    Enter password:
  49.  
    Welcome to the MySQL monitor. Commands end with ; or \g.
  50.  
    Your MySQL connection id is 2
  51.  
    Server version: 5.1.66 Source distribution
  52.  
     
  53.  
    Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
  54.  
     
  55.  
    Oracle is a registered trademark of Oracle Corporation and/or its
  56.  
    affiliates. Other names may be trademarks of their respective
  57.  
    owners.
  58.  
     
  59.  
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  60.  
     
  61.  
    mysql> show global variables like 'port';
  62.  
    +---------------+-------+
  63.  
    | Variable_name | Value |
  64.  
    +---------------+-------+
  65.  
    | port | 3506 |
  66.  
    +---------------+-------+
  67.  
    1 row in set (0.00 sec)
  68.  
     
  69.  
    mysql>
  70.  
     
  71.  
    总结:注意修改的端口不要被占用,而且要有规划,不要轻意的总是调整数据库端口。还有就是安全保障,记得与负责网络的人提前通知,以免端口无法正常使用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值