Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

All Good:

Mysql server installed just fine by using the following command:

sudo apt-get install mysql-server

During installation I was prompted to choose a root password. After install I was able to log in to mysql monitor using this command:

mysql -u root -p

and when prompted I entered the password and logged in successfully.

Problem:

When I reboot my server and then try to login to mysql monitor, upon entering the password I get this error:

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

When I look in /var/run/mysqld/ I do not see any file called mysqld.sock. Previously before the reboot there was a file by that name in that location. It was also highlighted red in my client shell program (mRemoteNG).

If I try to create that file by doing:

sudo touch mysqld.sock

It does get created but it isn't highlighted red, and when I try to login again, I get the same error as before.

I have tried uninstalling and reinstalling mysql and mysql-server countless times and the same issue arises every time.

I also tried stropping and starting mysql service and that didn't make any difference.

Note:

I am only prompted to choose a password during the very 1st install of mysql-server on a clean Ubuntu install. After that whenever I uninstall and reinstall it, it doesn't prompt me to choose a password, just says it has been installed successfully.

Question:

How to properly install mysql-server so that it will always be there even after rebooting the server?

share|improve this question

4 Answers 4

First, delete the mysqld.sock file you created - the server will create that automatically, and having a file there may cause it not to start anymore.

Install it with apt-get install mysql-server (like you said).

Reboot. If it's not running after the reboot, do "sudo /etc/init.d/mysql start"

Check that it's running now. If not, look in /var/log/mysql and /var/log/daemon.log for any error messages

To make it always start on boot, run "update-rc.d mysql defaults"

share|improve this answer

Depends on the distro, you shouldn't need to manually create the socket file.

Use chkconfig (CentOS):

chkconfig --level 345 mysqld on

Or create a symlink to the run levels you want the service executed on:

# Mysql Startup
ln -s /etc/init.d/mysqld /etc/rc.d/rc3.d/S85mysqld
ln -s /etc/init.d/mysqld /etc/rc.d/rc4.d/S85mysqld
ln -s /etc/init.d/mysqld /etc/rc.d/rc5.d/S85mysqld

# MySQL clean shutdown
ln -s /etc/init.d/mysqld /etc/rc.d/rc0.d/K85mysqld
ln -s /etc/init.d/mysqld /etc/rc.d/rc6.d/K85mysqld

When you say you've tried starting/stoping the service and that didn't do in anything, do you mean that: It did nothing in terms of auto-starting after reboot, or that it did nothing in terms of starting the mysql service period?

EDIT: Just realized you tagged the post with Ubuntu, Checkout Ubuntu's upstart scripts if you are on 10.04+, seems like aptitude should have dropped one in for you upon installation. Checkout the logs in /var/log/mysql(d) also if you think it's configured to autostart and is failing to do so.

share|improve this answer

Make sure it's configured to start up properly upon reboot. This typically means running "update-rc.d mysqld defaults" (or something very similar). update-rc.d will create symlinks from /etc/init.d to the startup script directories, e.g., /etc/rc3.d.

I don't know if mysqld starts off using Upstart on your version of Ubuntu. There will be a similar process to get the mysqld start script into /etc/init in that case.

share|improve this answer

The way to get mysql-server installed and running on Debian or Ubuntu is literally apt-get install mysql-server.

If that doesn't work you have another problem, best solved by going to the logs and trying to work out why it doesn't start - the problem is absolutely not how you installed it.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.