If you are using MySQL database server installed on the Linux server and you are not aware on which port it is listening then this tutorial is for you. In this tutorial you learn "How to find the default port number of MySQL in Linux?". After find the port number you can connect to the MySQL server through your program.
First of all you should have access to the machine on which MySQL is running.
Login as root on the machine running MySQL server and then type mysql on the console. If you are able to login to the mysql using this then use the following sql command to find out the port number of MySQL server:
mysql> show variables like 'port'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3306 | +---------------+-------+ 1 row in set (0.01 sec) mysql>
The above sql will show you the port number of MySQL server.
If you are not able login to mysql then you can use the following command on the Linux console:
lsof -i4 -P | grep -i mysql
Following command will give you following output:
root@mail [~]# lsof -i4 -P | grep -i mysql
mysqld 23062 mysql 10u IPv4 ******* TCP *:3306 (LISTEN)
Here you can see the that this command is giving you the port number.
You can also find the port number from the /etc/my.cnf file. You can open the my.cnf file and look for the variable:
port = 3306
In this you have learned how to find the port number of MySQL server running on Linux machine.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial
Discuss: MySQL default port number in Linux
Post your Comment