PDA

View Full Version : Solving MySQL ERROR 2002



Shark
19th July 2004, 04:19 PM
Hello guys, this is how I got MySQL-4.0.20 (source distribution) working, I've been stuck with the '2002 ERROR' complaining about the 'mysql.sock'


ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

First, I copy a configuration file, in somewhere like 'support files', choose 'my-medium.cnf' or 'my-large.cnf' .... and paste it in /etc/my.cnf, yes change the name to 'my.cnf'.

In that file you can change the path to the socket file, 'Socket = /path/to/socket'.
Another thing I did is make a empty 'mysql.sock' file and place it in the 'path/to/socket(you can also copy it somewhere from the installation package).

And before to launch the

/usr/local/mysql/bin/mysql I did

/usr/local/mysql/bin/mysqld_safe &

so : my.cnf, the sock file 'mysql.sock', and 'mysqld_safe' ...
Hope this will help.

alex3
27th November 2005, 09:34 PM
Hello guys, this is how I got MySQL-4.0.20 (source distribution) working, I've been stuck with the '2002 ERROR' complaining about the 'mysql.sock'


ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

First, I copy a configuration file, in somewhere like 'support files', choose 'my-medium.cnf' or 'my-large.cnf' .... and paste it in /etc/my.cnf, yes change the name to 'my.cnf'.

In that file you can change the path to the socket file, 'Socket = /path/to/socket'.
Another thing I did is make a empty 'mysql.sock' file and place it in the 'path/to/socket(you can also copy it somewhere from the installation package).

And before to launch the

/usr/local/mysql/bin/mysql I did

/usr/local/mysql/bin/mysqld_safe &

so : my.cnf, the sock file 'mysql.sock', and 'mysqld_safe' ...
Hope this will help.


Hi,

I have the same problems. From where do you copy the confiuraion file?

Thanks,



from where

DRE.ORGY.NET
28th November 2005, 08:22 AM
Its a permission problem. The user your trying access /var/lib/mysql/mysql.sock as doesnt have permission to that folder. You should be running mysqld as another user and this user should have full access to /var/lib/mysql/*

oxman
28th November 2005, 03:42 PM
That doesn't make sense to me. i have tried to start MySQL as a user and as root to no avail. Could you please be more specific on how to remove this error? I have done a thurough search for the mysql.sock file and it does not exist on my system hense the error. The server does not start at bootup and any attempt to start mysql from the CLI fails with this error:

Starting MySQLCouldn't find MySQL manager or server

When I do > mysqladmin -u root ping

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'

DRE.ORGY.NET
30th November 2005, 08:28 AM
I am pretty sure that if you run the init.d script ( /etc/init.d/mysql or /etc/init.d/mysqld depending how you installed it) it will change to the mysql user regardless.

How to fix it chown -R mysql:mysql /var/lib/mysql (replace mysql:mysql with appropiate user and group). If you want to check this before you do it try doing an ls -la /var/lib

This is my output for the mysql directory
drwxr-x--- 5 mysql mysql 4096 Nov 29 18:33 mysql

if your output is like the one below its because only root can write to that directory.
drwxr-x--- 5 root root 4096 Nov 29 18:33 mysql

I had the exact same problem and what I did was what I mentioned above and it worked like a charm.

Note: Also you might need to add other users to the mysql group if you are going to use mysql administrator as it will need direct access to the mysql.socks file too.

oxman
30th November 2005, 04:59 PM
I haven't tried this yet so YMV.
I did ls -al on /var/lib/. The result was that /var/lib/mysql was owned by 27. That correct. The user was number 27 and should have been mysql. Here is a reply I received from the L4C (Linux for Christians) list I am on.

Make sure that if everything is coming up as owned by '27' that when you create the mysql user, you make his user ID 27, homedirectory wherever mysql is, and the shell /bin/false:
Eg.
useradd -u 27 -s /bin/false -d /var/lib/mysql -G mysql mysql
Also note that -G for primary group. I'm using Gentoo and portage creates a mysql group. I don't know what the situation is for FC.
You won't need to change ownership of anything then, because it will suddenly "magically" translate the '27' into 'mysql' and be able to run.
The mysql package was not creating a mysql user

wroscoe
13th March 2008, 04:54 PM
I had this same error and apparently it was because mysql was not started. I followed the instructions listed here http://www.thescripts.com/forum/post266499-2.html and copied below and its working great now.

chkconfig --level 35 mysqld on
/etc/init.d/mysqld start

Fresco
28th July 2013, 03:34 PM
I've been trying to resolve this #2002 mysql error too. Those instructions (http://upcode.tk/phpmyadmin-error-2002-cannot-log-in-to-the-mysql-server/) has helped me! Wanted to share with you :)

DBelton
29th July 2013, 02:15 AM
Hmmm.. Original post was over 9 years ago.. last post was over 5 years ago.. I say this was a dead post you resurrected :)

Closing it up for good this time :p