Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
I'm getting the following error message:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
so I ran:
find / -name mysql.sock
and it doesn't show up, what should I do now? I'm using Mandrake 10.1 and this is the first time I'm using mysql. Should i try uninstalling mysql and reinstalling. I also noticed that there was an error file in
/var/lib/mysql
which had this in it:
50124 23:05:00 mysqld started
^G/usr/sbin/mysqld: Can't read dir of '/root/tmp/' (Errcode: 13)
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
050124 23:05:00 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
050124 23:05:01 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
050124 23:05:01 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
050124 23:05:02 InnoDB: Started
/usr/sbin/mysqld: ready for connections.
Version: '4.0.20' socket: '/var/lib/mysql/mysql.sock' port: 0
050124 23:05:02 /usr/sbin/mysqld: Normal shutdown
You can fix all of these problems through my.cnf, which is usually found at /etc/my.cnf
To get rid of those innodb errors (if you don't plan on using innodb), use this:
skip-innodb
If you don't plan on remote systems attaching directly to your database, and you're also running Apache on the system and want to interface the two, perhaps with a scripting language, enter this as well:
skip-networking
That will stop MySQL from running on anything but a socket (sockets are faster than tcp/ip access).
As for not finding the mysql.sock file,
Try:
Code:
find / | grep "sock"
and see what pops up.
Once you find it, you can enter the location here:
socket = /var/lib/mysql/mysql.sock
Just for a reference, here is my "my.cnf". It's a copy of my-medium.cnf (low memory in this system).
Quote:
# Example mysql config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# a important part and systems up to 128M very MySQL is used together with
# other programs (like a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
# ~/.my.cnf to set user-specific options.
#
# One can in this file use all long options that the program supports.
# If you want to know which options a program support, run the program
# with --help option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
skip-networking
skip-innodb
# Point the following paths to different dedicated disks
#tmpdir = /tmp/
#log-update = /path-to-dedicated-directory/hostname
# Uncomment the following if you are using BDB tables
#set-variable = bdb_cache_size=4M
#set-variable = bdb_max_lock=10000
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#set-variable = innodb_buffer_pool_size=16M
#set-variable = innodb_additional_mem_pool_size=2M
# Set .._log_file_size to 25 % of buffer pool size
#set-variable = innodb_log_file_size=5M
#set-variable = innodb_log_buffer_size=8M
#innodb_flush_log_at_trx_commit=1
#set-variable = innodb_lock_wait_timeout=50
Originally posted by welery thanks. I think all it needed was a reboot
If that fixes it, I would say you have a strange situation indeed. Microsoft users have grown to accustomed to rebooting a Windows system to fix a problem, but rebooting should not fix yours.
If the problem is gone, then great, but it will probably surface again.
Those errors mentioned are innodb errors, and adding noinnodb to my.cnf will get rid of those.
I think the problem was that I jsut installed mysql and the actual process that it needs to run wasn't running. I wasn't exactly sure how to run it. I probably could have ran it with a command of some sort but when i rebooted it started the process again so mysql worked. I still also did add noinnodb to my.cnf and that removed the errors. but the original error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' was cause because mysql process wasn't running
If that fixes it, I would say you have a strange situation indeed. Microsoft users have grown to accustomed to rebooting a Windows system to fix a problem, but rebooting should not fix yours.
If the problem is gone, then great, but it will probably surface again.
Those errors mentioned are innodb errors, and adding noinnodb to my.cnf will get rid of those.
thats just silly you cant fix a linux box by rebooting it lol.... i wish that was all i had to do!
i fixed my system by adding skip-networking skip-innodb to my.cnf
Yes we all know rebooting is nooby. However I think it may sort out some problems, such as restarting apache... etc
All I can say is that if restarting is your solution for your linux server you will have learned nothing of why the error had been occuring in the first place.
You need to start the mysqld daemon, varies depending upon your distribution. To see if mysql is running, open a terminal and type: ps -e | grep my; if it is not post back with distribution you are using.
I had the same problem after a fresh install of mysql. I fixed it by installing mysql-server, then running /etc/init.d/mysqld start. That worked for me.
Last edited by The Hound; 09-13-2011 at 11:21 AM.
Reason: spelling error
I had the same problem after a fresh install of mysql. I fixed it by installing mysql-server, then running /etc/init.d/mysqld start. That worked for me.
I had this error too after fresh install in CentOS. The above suggestion fixed it for me. Thanks Hound. Also Thanks Linux Questions! First and only stop for fixing this one... I Be Back! 8^D
I had this same problem on a Ubuntu 11 virtual machine running on vmware server 2.0. It turned out that I had broken my /etc/network/interfaces file. Once I got the loopback portion of the file corrected, MySQL came back fine.
For me, it was making sure that the following lines were in the /etc/network/interfaces file:
auto lo
iface lo inet loopback
When you connect to MySQL via the local machine using # mysql -uusername -ppassword it tries to connect to 127.0.0.1 (local loopback) However, if you’ve botched your interfaces file as I had, your mysql gets screwed. I tried uninstalling everything mysql but that didn’t work. I even made sure that I went through the entire filesystem and deleted every file and directory with “mysql” in it’s name and then reinstalling. No luck. But when I got my interfaces file corrected, everything was fine.
see # man interfaces for a little help on the file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.