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?
Asked
Active
Viewed 1,785 times
0

EdTan
- 38
- 5
-
1mariadb connects via a unix socket by default. Its a bit odd that a port is ignored until a host is specified. Its been that way for a long time. – danblack Sep 05 '20 at 09:22
-
Hello @danblack, thank you for replying. I see, noted. – EdTan Sep 08 '20 at 04:23
2 Answers
2
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

Georg Richter
- 5,970
- 2
- 9
- 15
-
Hi! Thank you for replying. I try that command and it works as expected, :D – EdTan Sep 04 '20 at 15:48
0
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 :)

RiggsFolly
- 93,638
- 21
- 103
- 149
-
Hi! Thank you for replying, I check it again and ready make sure, it's on the right configuration file /etc/mysql/mariadb.conf.d/50-server.conf and under section [mysqld], it's actually me not stating the host when connecting with the mariadb server. The solution provided by @georg work perfectly. – EdTan Sep 04 '20 at 15:52
-
or use `[client-server]` and configure the port for both one hit. If you look at `mysqld --help --verbose` it shows which sections are read. – danblack Sep 05 '20 at 09:24