- How to view MySQL default port number and modify port number 2015-03-19 17:42:18
- 1. Log in to MySQL
- [Email protected]/]# mysql-u root-p
- Enter Password:
- 2. Use the command show global variables like ' port '; View port number
- MySQL> show global variables like ' port ';
- +---------------+-------+
- | variable_name | Value |
- +---------------+-------+
- | Port | 3306 |
- +---------------+-------+
- 1 row in Set (0.00 sec)
- 3. Modify the port, edit the/etc/my.cnf file, the earlier version may be the my.conf file name, add the port parameter, and set the port, note that the port is not used, save exit.
- [Email protected] 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
- [Email protected] etc]#
- 4. Restart MySQL
- [Email protected] ~]#/etc/init.d/mysqld restart
- Stopping mysqld: [OK]
- Starting mysqld: [OK]
- 5. After logging in again, check that the port has been modified to ' 3506 '.
- [Email protected] 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), Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of the Oracle Corporation and/or its
- Affiliates. Other names 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>
- Summary: Note that the modified port should not be occupied, and planning, do not light always adjust the database port. There is security, remember with the person responsible for the network advance notice, so that the port can not be used properly.
cent7.0 MySQL Modify port