7

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 
arielf
  • 5,802
  • 1
  • 36
  • 48
SIFE
  • 5,567
  • 7
  • 32
  • 46
  • Why would you want this? Can you explain the reason behind it? If this is for security (no remote access) reason you can allow only localhost access by commenting out the bind-address directive in my.cnf i.e have bind-address = 127.0.0.1 there – arielf Mar 11 '13 at 00:48
  • 4
    I don't need any remote access. – SIFE Mar 11 '13 at 00:54
  • Is there a performance benefit to using sockets only? – Drew Hammond Oct 01 '14 at 22:42
  • Yes, using sockets bypasses all the unnecessary tcp protocols. It is very minimal like 40ms saving, but it may be worth it. https://jasonbarnabe.wordpress.com/2014/10/01/mysql-connections-sockets-vs-tcp/ – ggedde Mar 06 '19 at 07:57

3 Answers3

3

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.

arielf
  • 5,802
  • 1
  • 36
  • 48
3

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.

SIFE
  • 5,567
  • 7
  • 32
  • 46
0

The parameter you are using seems to be correct, if you want to limit the connections to your mysql server only to local connections, I should add this lines to /etc/my.cnf

[mysqld]
bind-address=127.0.0.1

Don't forget to restart the mysqld service for the configuration changes to be activated

  • Removed the use of skip-networking, which is not needed
jhcaiced
  • 716
  • 8
  • 11
  • 2
    `skip-networking` will disable the tcp functionality on the server, so even if I add `bind-address`, this will be directive will overridden by `skip-networking`. – SIFE Mar 19 '13 at 04:58
  • @SIFE is correct. `bind-address` becomes a noop when `skip-networking` is specified, according to the [manual](https://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_skip-networking): "`--skip-networking` Do not listen for TCP/IP connections at all. All interaction with mysqld must be made using named pipes or shared memory (on Windows) or Unix socket files (on Unix). This option is highly recommended for systems where only local clients are permitted." – Adrian Günter Jul 30 '15 at 18:02