cent7.0 mysql 修改端口

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