HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

How does one change the default socket used by mysqladmin?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
theusedmysqladminonedefaultdoeshowsocketchange

Problem

How does one change the default socket used by mysqladmin?

I don't see a section for [mysqladmin] in /etc/my.cnf.

It tries by default to connect to /tmp/mysql.sock, however, this is not the socket that my MySQL server uses, so I get the error:

error: 'Can't connect to local MySQL server through 
    socket '/tmp/mysql.sock'


I know you can specify the socket at the command line, such as:

mysqladmin --socket='/some/other/path/mysql.sock'


How do I change the default socket used by mysqladmin so I don't have to specify my non-standard path each time?

Solution

Add a [mysqladmin] section in your /etc/my.cnf or $USER/.my.cnf and set the socket. This will override the compiled-in socket and the socket defined in the [mysqld] section.

You should be able to figure it out from what's shown below:

VM52-CentOS58[root@ivdb41 ~]# mysqladmin ping

mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql2.sock' (2)' Check that mysqld is running and that the socket: '/var/lib/mysql/mysql2.sock' exists!

VM52-CentOS58[root@ivdb41 ~]# grep -A 1 mysqladmin /etc/my.cnf

[mysqladmin]
socket=/var/lib/mysql/mysql2.sock

VM52-CentOS58[root@ivdb41 ~]# mysqladmin ping mysqld is alive

VM52-CentOS58[root@ivdb41 ~]# grep -A 1 mysqladmin /etc/my.cnf

[mysqladmin]
# socket=/var/lib/mysql/mysql2.sock

Code Snippets

VM52-CentOS58[root@ivdb41 ~]# mysqladmin ping

mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql2.sock' (2)' Check that mysqld is running and that the socket: '/var/lib/mysql/mysql2.sock' exists!

VM52-CentOS58[root@ivdb41 ~]# grep -A 1 mysqladmin /etc/my.cnf

[mysqladmin]
socket=/var/lib/mysql/mysql2.sock

VM52-CentOS58[root@ivdb41 ~]# mysqladmin ping mysqld is alive

VM52-CentOS58[root@ivdb41 ~]# grep -A 1 mysqladmin /etc/my.cnf

[mysqladmin]
# socket=/var/lib/mysql/mysql2.sock

Context

StackExchange Database Administrators Q#24281, answer score: 2

Revisions (0)

No revisions yet.