Bug #4174 mysql.sock doesn't exist
Submitted: 17 Jun 2004 0:07 Modified: 17 Jun 2004 0:17
Reporter: [ name withheld ] Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:4.0.20 OS:Linux (Linux RH8,RH9,and Fedora)
Assigned to: Matthew Lord CPU Architecture:Any

[17 Jun 2004 0:07] [ name withheld ]
Description:
can't connect to MySql database, can't find mysql.sock where it is supposed to be.  I have read all the bugs concerning this problem.  Yes, I have tried to start MySqlAdmin, same result.  Same result for starting MySqld. They all make reference to moving the file or making a link.  This only works if you have a mysql.sock file to work with.  The file doesn't exist, and I cannot find any references on how to build my own sock file.

This problem exists with multiple Linux distros, and I have tried different versions of MySql(on CD's, downloaded binaries, installed from rpm's) with the same result each attempt.

The really ironic thing about this, I installed a Windows version on my XP and it works fine.

How to repeat:
Try to start MySql, the error happens every time.
[17 Jun 2004 0:17] Matthew Lord
Depending on your installation method the mysql.sock file will be created in /tmp/ /var/run/mysql 
beneath your installation.  Please make sure that you are following the installation instructions.  When 
you start up mysqld, /etc/init.d/mysql.server start or ./bin/msyqld_safe & for example, the socket will 
get created.  On all of these systems you should be able to do bash#locate -u && locate mysql.sock to 
see where it is located is the server is in fact running.

Best Regards
[14 Feb 2007 22:42] guildof druids
try this 

#cd /etc/rc.d/init.d

# ./mysqld start

it should come up with the following 

Initializing MySQL database:  Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h linuxserver password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
Starting MySQL:                                            [  OK  ]

thats it !! 

now try 

#mysql (if you are already logged in as root otherwise 
#mysql -u root -p 

cheers !
[28 Nov 2007 9:35] sunith dodda
Hello, I in the begining got the mysql5.0.20a*.tar file, and extracted to a "mysql5.0.20a*" directory. I cd into the bin directory, and tried to start the mysql instance, But it was throughig the following error,
"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)", 
so I insalled perl.rpm and Mysql*.rpm on my system. Even now I am not able to use that instance. but i can use the mysql when i run from "/etc/init.d/mysql -u root -p" here, was this executable file using my extracted tar bundle (or) was this a diffrent way of installation. 
Can you give me some explanation on this. Thanks in advance.
[10 Aug 2009 19:00] Townsend Thomas
I have been chasing mysql.sock for days.  Tried several distros, including Ubuntu 9.04.  In 9.04 at least running mysqld_safe & doesn't generate a mysql.sock file, it opens and hangs.  Nor does ./mysqld start, just more error messages.  mysql.server does not exist in init.d.  rc.d doesn't exist in /etc.  Mysql-5 works great in Windows.  Help!
[20 Oct 2009 4:06] Sandhi Firmadani
Hello, 

I just wanna to share my problem...

Here is the following weird condition:
1. I check the service and said mysqld (pid 3808) is running...
2. But when i try to login, mysql said error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)' 
3. When i check to those /var/lib/mysql directory, there is no mysql.sock.

Anyone know this issue ?

MySQL version : 5.0.45
OS version : Fedora release 7 (Moonshine)
Kernel version : 2.6.21-1.3194.fc7
Using Plesk Control Panel 8.3
Web Hosting Server with 122 clients and medium load trafic
[4 Mar 2010 7:35] Muhammad Rafique
It works well with 
# cd /etc/init.d
# ./mysqld start
thank you
do not forget to insert ./
[5 Aug 2010 17:34] Bryson Black
This worked for me:

mysql --user=username --password=password
[10 Nov 2010 16:42] mosiah parkman
here is the command to use after installing from source or other methods:

mysqladmin -u root -h yourServersHostname password 'yourNeWpassword'

Doing this it will not complain about the mysql.sock 

when logging in make sure to use the -h to tell mySQL the name of your server, because default is localhost:
mysql -u root -h yourServersHostname -p

Then mySQL will prompt you for your password
Enter password:

Do so and connect!
Hope this helps.
[10 Feb 2011 19:14] Robert Gray
Not to be funny guys, but if you are accessing local server just put in 
socket = MySQL

Or...

socket = path/to/your/base/dir
do not add mysql.sock at end, just the base directory path and that is it done.