Change Port Of MySQL In XAMPP

XAMPP is a cross-platform open-source server solution stack that includes an interface for managing both Apache Server (Web Server) and MySQL Server (Database server). Because of the ease of access to the Apache Server and MySQL Server, we generally use XAMPP for developing PHP-based or WordPress-based web applications.

When using XAMPP to create a PHP application or a WordPress site, you may encounter a port issue with either Apache or MySQL server.

In this section, we’ll talk about the issues you’re having with MYSQL Server.

MySQL Server’s default communication port for TCP/IP connections is 3306. However, you may find that these ports are already in use by other applications or that the computer has blocked them for security reasons. As a result, your MYSQL will stop working, and in this case, you can change the port of the MYSQL Server to something like 3307,3308, and so on.

In Passioncoding, we will learn how to change the port of MYSQL in the XAMPP Stack as follows:

1 First, launch the XAMPP Control Panel.

2 Then, under MySQL, click on Config button.

3 Next, in the popup, select the my.ini option.

my.ini is a file that contains configuration settings files that will be loaded when the MySQL server is first started, including settings for the clients and server, mysqld_safe wrapper, and various other MySQL client programs.

4 Then, somewhere around line 20, you’ll find a port 3306, as shown below.

# password = your_password
port= Simply change the number from 3306 to something higher. Say 3307 or 3308 instead.

# password = your_password
port= For simplicity, I have used 3307 port

6 On the same file, around line 28, you will find the configuration shown below.

[mysqld]
port= Just change port 3306 to 3307 as below.

7 Close the XAMPP Control Panel and reopen it, then try to restart MySQL from XAMPP Control Panel. If you are still unable to start the MySQL Server service, restart your computer.

After changing the MySQL port, you must connect your PHPMyAdmin and localhost to MySQL port 3307. To do this, do the following.

8 Click the config button under Apache in XAMPP Control Panel, and then the config.inc.php.

This will open the config.inc.php file in a default text editor. There find below the line.

$cfg[‘Servers’][$i][‘host’] = ‘127.0.0.1’;

Then change this line to:

$cfg[‘Servers’][$i][‘host’] = ‘127.0.0.1:3307’;

9 Now onward for every project you have to change MySQLi connection string configuration in your PHP projects as shown below.

$conn = mysqli_connect(“localhost” , “root” , “”, “database_name”);

$conn = mysqli_connect(“localhost:3307” , “root” , “”, “database_name”);