Change MariaDB 10.5.5 Port

2k Views Asked by At

I have installed MariaDB 10.5.5 in Ubuntu 20.04 server. Right now I try to change the default port of the database to let say 12345. When I look into /etc/mysql/my.cnf and /etc/mysql/mariadb.conf.d/50-server.conf there is no port options, then I add port = 5505 inside /etc/mysql/mariadb.conf.d/50-server.conf under [mysqld], then I restart the mariadb-server using sudo systemctl restart mysql & sudo systemctl restart mariadb. But when I connect the mariadb server using mysql -uusername -p, it's just connected. The expected behavior is mysql client will reject the connection. I also try to use mysql -uusername -p -P123222, but still connected. My questions is how can I can change the port and prevent this strange behavior to happen?

2

There are 2 best solutions below

1
On BEST ANSWER

Unless you don't specify a hostname, the default hostname "localhost" will be assumed, so the connection will be established via unix_socket and not via TCP/IP.

To connect via port use e.g.

mysql -h127.0.0.1 -P12345 -uusername -p
2
On

There are 2 places, at least, where you may find the

port = 3306

Make sure you are changing them all, but specifically the one under the section [mysqld]

[mysqld]
port = 3307

It is this one that tells the deamon which port to use.

My guess is you changed the one under [client]

So change both :)