Keywords: MySQL | Port Configuration | my.ini File
Abstract: This article provides a comprehensive guide on changing MySQL server's default port from 3306 to 3360. It explains the configuration file modification process, details the static nature of port parameters as system variables, and offers step-by-step instructions for Windows environments. The paper also compares different configuration approaches and their suitable application scenarios.
Fundamentals of MySQL Port Configuration
The port configuration of MySQL server is a system-level parameter that requires modification through configuration files. Unlike dynamic variables, port parameters are read during MySQL startup and cannot be altered in real-time using SQL queries. This design ensures service stability and security.
Configuration File Modification Procedure
In Windows systems, MySQL's configuration file is typically named my.ini and located in the C:\ProgramData\MySQL\MySQL Server 5.7\ directory. Open this file with a text editor, locate the configuration line containing port=3306, and change it to port=3360. After saving the file, restart the MySQL service through the service manager to apply the changes.
Service Restart and Verification
After modifying the configuration file, the MySQL service must be restarted. In Windows 8, locate the corresponding MySQL service (such as MYSQL57) in the Services tab of Task Manager and perform a restart. Once the service restarts, verify the configuration using the command-line tool: mysql -u root -p -P 3360.
Analysis of Alternative Configuration Methods
Besides modifying the configuration file, the port can be specified via command-line parameters during MySQL startup: mysqld --port=3360. This method is suitable for temporary testing or scripted deployment scenarios but is less persistent and stable than configuration file modifications. Note that command-line parameters override settings in the configuration file.
Configuration Considerations
Before changing the port, ensure the new port is not occupied by other services and add firewall rules to allow traffic on the new port. For production environments, it is recommended to backup the original configuration file before making changes and choose non-standard ports to enhance security.