Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm fairly new to Linux, when I first installed MySQL it was during an LAMP setup on personal machine with a Ubuntu Setup. ATM, I'm trying to get a fresh, clean install of only MySQL. I've been to trying to research how to fix this error:

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

But realized it's a wild goose-chase, this seems to be a common problem, with a number on solution of it not running in the background. Any Who, I still can't find out what my issue is and I know there is nothing important in this database, so:

 sudo apt-get purge mysql-server mysql-client

Or probably does work, but there is still (conf) files of it saved somewhere. What subdirectories/directories would I have to go into and do a 'sudo rm -f [db_files]' on. (Or other apt-get purge(s) am I missing)

share|improve this question

migrated from stackoverflow.com Apr 21 '12 at 9:58

This question came from our site for professional and enthusiast programmers.

    
Your error indicates that mysql was not running on the machine when you tried to connect to it, you could have tried running the server manually by running sudo /etc/init.d/mysqld. As for removing configuration files, apt-get purge should have done that, otherwise try sudo dpkg -P mysql-server or manually remove /etc/mysql/. As for database files, the default Ubuntu install location for them is, I want to say, /var/db, but I don't use Ubuntu so I don't know. Also, you might want to take this to askubuntu.com, which is the StackExchange site for Ubuntu users. –  birryree Apr 19 '12 at 15:45

4 Answers 4

What this error message says is "I am unable to connect throught a local file" which can mean either mysqld is not running or it is configured to disable socket or it is in another place.

To completly reinstall mysql :

1) Purge totally mysql packages : apt-get purge mysql mysql-server mysql-common mysql-client (depends on distributions). You can check for remaning packages with dpkg -l | grep mysql

2) Check that the configuration file is gone. It should be under /etc/my.cnf or /etc/mysql/my.cnf. You can make sure by doing find / -name my.cnf. (Note : anything under /usr/share are documentations and example configuration and should not make problems)

3) Remove or move the directory /var/lib/mysql which containe (old) database files

4) apt-get install mysql-server && /etc/init.d/mysqld start should get you a fresh new mysql install.

5) If the error remains, check that mysqld is running using command ps -ef | grep mysqld. If it is, you may want to specify the "sock" parameter under "[mysqld]" in the configuration file names in 2). You can also try to connect using mysql -h 127.0.0.1 --protocol=TCP to force a network connection instead of using UNIX sockets.

share|improve this answer
    
How did this question reached the top ? didn't see it was from a year ago. The problem is probably long gone... –  Kwaio Aug 14 '13 at 8:32

mysql removiing and reinstall process;

Step 1: Uninstall existing rpms using yum

# yum remove mysql mysql-server

Step 2: Remove or move /var/lib/mysql folder.

# mv /var/lib/mysql /var/lib/mysql-bak

Step 3: Reinstall mysql again using yum.

# yum install mysql mysql-server

Step 4: Now mysql service will start successfully.

share|improve this answer
2  
from the use of apt, he's probably not on centos or RHEL - as they question says he runs ubuntu –  Journeyman Geek Aug 14 '13 at 7:04

All database files of mysql are usually stored in /var/lib/mysql.

But your problem seems to be somewhere else: /var/run/mysqld/mysqld.sock is the default position for this files.

Look at the log files /var/log/mysql.err and into /var/log/syslog to track down the error why mysqld does not want to run.

share|improve this answer

The setting you are looking for is defined in the mysql config file located in /etc/mysql/ a purge will very likely not affect files which are located in etc especially if they have never been created at the install time(originally created by LAMP).

  1. Purge all mysql stuff as you do above
  2. Locate the config file in the given directory /etc/mysql , if you cant find it use "find" searching for '/var/run/mysqld/mysqld.sock' , it should also be in the configuration file where the default socket lies around
  3. Remove the config file
  4. Reinstall Mysql

If you have any issues, ask.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.