MySQL Default Port Change Ubuntu 20.04LTS

Hi, I am having issues figuring out how to change my default port number for MySQL. I have done it in the past, but now I cannot remember what file I need to change and its location for Ubuntu 20.04LTS.

Any assistance would be great!
Thank you!

1 Reply

Typically, MySQL's configuration files are located in /etc/mysql. You can check the actual location of your config file by using the below command:

/usr/sbin/mysqld --help --verbose | less

At the begining of this output, you will see something similar to what I include below. My config is in the .my.cnf file.

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

From there, you will look for the port option in the file. If it's missing, that may mean it is using the default 3306. In that case, you can just add the below text to the end of the file.

[client]
port = 3306

[mysqld]
port = 3306

Additional Resources*

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct