1. Log in to MySQL[email protected]/]# mysql-u root-pEnter Password:Welcome to the MySQL Monitor. Commands End With; or \g.Your MySQL Connection ID isServer 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 itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement. mysql>
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=3506datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql # Disabling Symbolic-links is recommended to prevent assorted security riskssymbolic-links=0 [Mysqld_safe]log-error=/var /log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid "My.cnf" 11L, 261C written[[email protected] etc]# 4. Restart MySQL[Email protected] ~]#/etc/init.d/mysqld restartstopping 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-penter password:welcome to the MySQL monitor. Commands End With; or \g.your MySQL connection ID is 2Server version:5.1.66 Source distribution Copyright (c) #, Oracle and/or its Affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. 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 view and modify the default port number