digitalFAQ.com Forum

digitalFAQ.com Forum (https://www.digitalfaq.com/forum/)
-   Website and Server Troubleshooting (https://www.digitalfaq.com/forum/web-tech/)
-   -   How to fix ERROR 2002 (HY000): Can't connect to local MySQL server through socket (https://www.digitalfaq.com/forum/web-tech/3832-how-fix-error.html)

kpmedia 01-16-2012 09:09 AM

How to fix ERROR 2002 (HY000): Can't connect to local MySQL server through socket
 
I always forget to change this setting when attempting to copy/paste somebody else's MySQL config file (my.cnf). :o

Always locate your original socket setting before overwriting your existing my.cnf
-- or if you're smart, before creating a new my.cnf after renaming the old one. I like to mv the old one to my.cnf.default, just in case.

For example, this is the proper socket for my dev server:
Code:

socket = /var/run/mysqld/mysqld.sock
I've been trying some tweaked variations of the lowendbox.com MySQL for low-RAM (128MB or less) servers:
Code:

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K
skip-innodb

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout

If I run this my.cnf file, I'll get an Error 2002 on the back end. For example, when trying to access MySQL with the mysql command.

Code:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Don't see the problem? Look again:
socket = /var/lib/mysql/mysql.sock
socket = /var/run/mysqld/mysqld.sock


Wrong location = MySQL will not start. Oops. --- Don't feel too stupid. I had to Google it, too. :P

This post, like many others, is a note to self. So much time passes between setting up servers (weeks to months), that I tend to forget some of the easy tasks. In the old days, we kept notebooks. Those were not as easy to search and forums and blogs, however, especially if you power your searches with Google's engine!

If you've come across this post, I hope it's helped you. And welcome to the site. :)

__________________

Need a good host? .Find one here: List of the Best Web Hosts in 2012 - Shared, reseller and VPS hosting

kpmedia 06-06-2012 03:11 AM

This can also happen on a new MySQL installation, where:
  1. You are trying to run mysql_secure_installation ...
  2. ... but MySQL is but not yet running! On Fedora, for example, installing a service does not also start it.

Simply CTRL-C out of the mysql_secure_installation, and start MySQL:
Code:

service mysqld start
Now try again. It should work fine. :thumb:


All times are GMT -5. The time now is 03:35 PM

Site design, images and content © 2002-2026 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2026 Jelsoft Enterprises Ltd.