When attempting to change MySQL's default port (3306) on Windows, many developers encounter the challenge of missing configuration files. MySQL searches for configuration in this order:
- %WINDIR%\my.ini
- %WINDIR%\my.cnf
- C:\my.ini
- C:\my.cnf
- INSTALLDIR\my.ini
- INSTALLDIR\my.cnf
When no configuration files exist (common with newer MySQL installations), you'll need to create one. Here's the proper way to create a working configuration:
# Example my.ini configuration [client] port=44999 [mysqld] port=44999 # Important: Add your existing configuration here basedir="C:/Program Files/MySQL/MySQL Server 5.5/" datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data"After creating/modifying the my.ini file, you must properly restart the MySQL service:
# Command line method (admin privileges required) net stop MySQL55 net start MySQL55 # Alternative using PowerShell Restart-Service -Name MySQL55 -ForceTo confirm MySQL is listening on the new port:
# Using command line netstat -ano | findstr 44999 # MySQL client verification mysql --port=44999 -u root -pIf the service fails to start after port change:
- Check Windows Event Viewer for MySQL errors
- Verify file permissions on my.ini (Administrators: Full Control)
- Ensure no other services are using the new port
- Add explicit bind-address if needed:
[mysqld] port=44999 bind-address=127.0.0.1For persistent configuration, modify the service definition:
# First find the current service binary path sc qc MySQL55 # Then update with new configuration file path sc config MySQL55 binPath= "\"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld\" --defaults-file=\"C:\Program Files\MySQL\MySQL Server 5.5\my.ini\" MySQL55"
Many Windows users struggle to find where MySQL actually reads its configuration. Unlike Linux systems where files are typically in /etc/my.cnf, Windows installations can be more ambiguous. MySQL searches these locations in order:
1. %WINDIR%\my.ini 2. %WINDIR%\my.cnf 3. C:\my.ini 4. C:\my.cnf 5. INSTALLDIR\my.ini 6. INSTALLDIR\my.cnfFor MySQL 5.5+ installations, the most reliable location is typically:
C:\ProgramData\MySQL\MySQL Server 5.5\my.iniThe minimal configuration needed to change ports requires these sections:
[client] port=44999 [mysqld] port=44999For a production server, you should also specify:
[mysqld] port=44999 bind-address=0.0.0.0 max_connections=200After modifying the configuration:
- Stop MySQL service:
net stop MySQL55
- Verify no mysqld process remains in Task Manager
- Start MySQL service:
net start MySQL55
Check active ports using PowerShell:
Get-NetTCPConnection -LocalPort 44999Or test connection from MySQL client:
mysql --port=44999 -u root -pCreate a new firewall rule for the custom port:
New-NetFirewallRule -DisplayName "MySQL Custom Port" -Direction Inbound -LocalPort 44999 -Protocol TCP -Action AllowIf MySQL reverts to 3306:
- Check for duplicate my.ini files
- Verify file permissions (Administrators: Full Control)
- Inspect error logs:
C:\ProgramData\MySQL\MySQL Server 5.5\Data\*.err