Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force MySQL to use only unix socket

I want my MySQL server to only use unix socket, and ignore the TCP networking, so I added this line to my configuration /etc/my.cnf:

skip-networking 

But netstat show me that MySQL still using TCP port 3306:

# netstat -tl | grep mys
tcp        0      0 *:mysql      *:*                         LISTEN 
like image 625
SIFE Avatar asked Mar 11 '13 00:03

SIFE


People also ask

Is it possible to connect to MySQL via Unix socket from another host?

"Unix sockets" are not TCP/IP sockets. They are always limited to the current system only – it is not possible to connect to another system's socket over the network. Because of that, the hostname localhost is special in MySQL and the client doesn't actually attempt to look up its IP address at all.

What socket does MySQL use?

MySQL manages connections to the database server through the use of a socket file, a special kind of file that facilitates communications between different processes. The MySQL server's socket file is named mysqld. sock and on Ubuntu systems it's usually stored in the /var/run/mysqld/ directory.

Does MySQL use TCP?

The default MySQL port 3306 is TCP (Transmission Control Protocol).


2 Answers

It turns that I saved the file as my.conf , witch it should be my.cnf, and that is why the server was only load and use the default configuration.

like image 182
SIFE Avatar answered Oct 10 '22 23:10

SIFE


If the reason is to prevent remote access, you can achieve your goal by having:

bind-address = 127.0.0.1

in the [mysqld] section of your my.cnf and restarting mysqld.

This ensures that mysqld would allow only local connections.

To prevent remote-access skip-networking is not the only option, as the comments in (2013) my.cnf say:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.

EDIT: The secure version (with the bind address above) is already the default in recent (as of 2013) Ubuntu versions, so you have to change it (comment the line above out) only if you actually want to enable remote serving.

like image 36
arielf Avatar answered Oct 10 '22 22:10

arielf