To find the [mysqld]
section, just open the configuration file in the terminal by typing sudo nano /etc/mysql/mysql.conf
.
Find the line that says "port = 3306" in it.
After changing it to an empty port, save the file.
Next, just restart the service, such as sudo service mysql restart
, or the VPS.
The following locations may contain the file mysql.conf
if it is not in the one I mentioned above: My.conf
, My.cnf
, and Mysql/My.conf
in /etc
.
Try these steps if the service command doesn’t function: sudo restart mysql /etc/init.d
.
If the issue continues, I would check iptables
or any other firewall-enabled option (I would actually erase everything in iptables
to start over, if that were possible).
Given that they are VPS, I would also look for any options to block ports in the VPS Control Panel.
Aside from that, I would check the ports you have opened on the VPS using nmap
.
To find out which ports they have opened, you have to run it from outside the VPS.
It’s also a good idea to use netstat -tuplen
to see which of your server’s open ports are in LISTEN
mode.
The next topic is how to open Linux port 3306 for MySQL.
To grant access to the MySQL port, follow these steps:
- Start by logging in as root to your server.
- Use this command to edit the Firewall configuration file (
csf
):NANO
,ETC
,CSF
, andCSF.COMF
. - Look for the lines that follow, as indicated in the illustration below:
# Allow incoming TCP ports TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,2077,2078,2079,2080,2082,2083,2086,2087,2095,2096,3306"
- Add the port number 3306 in the following manner.
- To save the changes and exit, press
CTRL+O
and thenCTRL+X
.
Let’s examine how to allow MySQL access to port 3306.
For MySQL users, port 3306 needs to be manually opened. Don’t do this on every workstation install; just the server.
- Click
Security
once the Control Panel is open. - On Windows Firewall, click.
- Click
Inbound Rules
underAdvanced Settings
. - Select "New Rule".
- Press
Port
and thenNext
. - Choose
TCP
.
Let’s get started on changing MySQL Ubuntu port 3306.
3306 is the port number that MySQL uses by default. It is possible to switch to any other available port instead of this one.
It is crucial to make sure that no other application is using the port when configuring it for MySQL.
Configuring ports for MySQL is a simple procedure. Either specify the port number when establishing a connection to the MySQL server, or modify the port number in the MySQL configuration file.
When connecting to the MySQL server, take the following actions to specify the port number:
- Get the MySQL client open.
- Use the following format to specify the host and port number:
mysql -u username -p -h hostname -P port_number
MySQL’s communication port by default is 3306, but you can set it to any other port that is open.