How to change mysql port number in centOS 7

How to change mysql port number in centOS 7

Default port of mysql is 3306 . To change the default port to custom port , Please follow the below steps :- 


Step 1 : First , use the below command to check the availability of port (port is free or not) .


Command : netstat -tanp|grep 3337



Step 2 : Open the mysql configuration file /etc/my.cnf .


Command :  vi /etc/my.cnf



Step 3 : In my.cnf find the [mysqld] section. Edit the port no. 3306 to 3337(or any) or if you do not find any such line you can add port = 3337 in my.cnf but it should be under the [mysqld] section as shown in the screenshot below .


Press ‘i’ for the insert mode . 



Now save and exit from the file using (backspace) :wq .


Step 4: Restart the mysql service .



Step 5 : To verify the port number of mysql , use the following command :


Command : # netstat -tlpn | grep mysql



Step 6 (Optional): If you have firewalld on your server , then open the required port by the following :


command : # firewall-cmd –permanent –zone=public –add-port=3337/tcp



Step 7 : Login to mysql with custom port using following command : 


Command # mysql -h localhost -u root -p -P 3337




THANK YOU !



    • Related Articles

    • Change SSH Default Port 22 to Custom Port

      1. Access your linux server using SSH with putty any third party software. 2. Enter your sudo user password or root password. 3. Open SSH configuration file using below command in your favorite editor. [root@ssh-port-change ~]# vi ...
    • Installation of Mysql server on CentOS 7

      MySQL is an open-source relational database management system . Its name consists a combination of ‘My’ and ‘SQL’ as the name for the Structured Query Language of the co-founder Michael Widenius’s daughter. Step 1: Login into the server using root ...
    • How to Install (Linux, Apache, MariaDB, PHP) LAMP Stack on CentOS 7

      LAMP, which operates Linux as the operating system, is an open-source web-developing platform using Apache as the web-based server and PHP as an object-oriented scripting language. (Instead of PHP, Perl or Python are sometimes used.) Prerequisites ...
    • INSTALLATION AND CONFIGURATION OF APACHE TOMCAT 9 ON CENTOS 7

      Apache Tomcat program is an open-source application of Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. Under the Java Community Process the Java Servlet, JavaServer Pages, Java Expression Language and Java ...
    • How to Install and Configure PowerDNS on centos 7 using MariaDB.

      PowerDNS is a DNS server that works on many derivatives from Linux / Unix. It can be configured with various backends, including zone files of the BIND style, relational databases and failover / load balancing. The DNS recurrent can also be set up as ...