Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm a newbie on MySQL ground so bear with me.

I've just finished upgrading 11.10 to 12.04.

Everything seemed to work without any hiccups and all my software and settings are working fine. Apart from MySQL.

When I try:

sudo start mysql

I receive an error:

start: Job failed to start

Where can I possibly diagnose what the problem is? And (hopefully) - how to sort it out?

(I disabled automatic start following advice here if that is of some importance)

Update 1:

Both outputs of:

cat /var/log/mysql.err 
cat /var/log/mysql.log

are empty.

Output of dmesg | grep mysql:

[ 1401.785141] type=1400 audit(1335619832.181:25): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=16165 comm="apparmor_parser"
[ 1401.791089] init: Failed to spawn mysql main process: unable to execute: No such file or directory

Update 2:

As indicated by AWinter below - it seemed that MySQL disappeared automagically after upgrade and had to be reinstalled.

share|improve this question
add comment

12 Answers

up vote 31 down vote accepted

Check that mysql-server-5.1 package was uninstalled, seems it might persist after upgrade. I had the same error and had to purge MySQL server 5.1 and 5.5 then re-install.

First make a backup of your /var/lib/mysql/ directory just to be safe.

sudo cp -R /var/lib/mysql/ ~/mysql

Next purge MySQL (this will remove php5-mysql and phpmyadmin as well as a number of other libraries so be prepared to re-install some items after this.

sudo apt-get purge mysql-server-5.1 mysql-common

Remove the folder /etc/mysql/ and it's contents

sudo rm /etc/mysql/ -R

Next check that your old database files are still in /var/lib/mysql/ if they are not then copy them back in to the folder then chown root:root

(only run these if the files are no longer there)

sudo mkdir /var/lib/mysql/
sudo chown root:root /var/lib/mysql/ -R
sudo cd ~/mysql/
sudo cp * /var/lib/mysql/ -R

Next install mysql server

sudo apt-get install mysql-server

Finally re-install any missing packages like phpmyadmin and php5-mysql.

share|improve this answer
Excellent. Worked as a charm. All working again. One note: I did not have to remove this directory sudo rm /etc/mysql/ -R - it was simply not present in my case. Anyway - luckily it was just a local install to test Wordpress.. Wonder what would happen on a real server o_O –  radek Apr 28 '12 at 14:01
apt-get --reinstall install mysql-server-x.x did the job for me. –  Yashima Apr 10 '13 at 20:27
This worked for me, but I should probably have done an apt-get update before hand, because it removed dovecot and php5-mysql. I could only reinstall these after the update. Once I had done, everything was once again working fine. –  AntonChanning Aug 6 '13 at 13:48
I get -bash: cd: /var/lib/mysql/: Permission denied and using sudo -i doesn't even work. –  Little Big Bot Mar 1 at 5:09
@LittleBigBot I made a change that should fix that. –  AWinter Apr 27 at 20:55
add comment
sudo dpkg-reconfigure mysql-server-5.5
share|improve this answer
Not a very friendly answer, but it worked for me :-) –  Joseph Jun 9 '13 at 9:16
Did not work for me :[ –  ThomasReggi Sep 23 '13 at 16:59
add comment

I had this same issue and for me it was the InnoDB logfiles were a different size than mysql was expecting, and failed silently during upgrade.

I had a custom configuration file that was wiped out on the upgrade to 12.04 that set the log file sizes to something other than what the default configuration.

You have to remove the files: /var/lib/mysql/ib_logfile*

After the files are gone, mysql can now start and create fresh log files of the default size.

share|improve this answer
Ahhh, thank you. This was my problem as well. –  UltimateBrent Sep 2 '12 at 15:26
Bingo. In our case a dev had altered some config settings for innodb (and neither he nor I knew that that could cause an issue). This prevented mysql from starting. Deleting those config files allowed MySQL to start. –  gaoshan88 Apr 10 '13 at 16:36
add comment

Most errors will show up by starting the server in debug/non-daemon mode and watching the output:

sudo mysqld --debug
share|improve this answer
I used sudo mysqld --verbose –  oleksii Feb 18 '13 at 14:36
add comment

I had the same problem, but none of the answers above helped me. So as a final hope I tried to free some disk space. I simply remove unnecessary log files from /var/log which freed some 2.5G space. Then MySQL started normally.

share|improve this answer
Yep, this was my problem as well. mysql was not starting during bootup, as it had been. Later was the System info that renders to the terminal; "Usage of /: 95.1%" So, there wasn't enough free space for mysql (and other processes) to start. I needed to do some file cleanup, and mysql started without a problem. –  Screenack Jul 4 '13 at 13:34
This was my case. Disc cleanup and Mysql start working. –  Sergey Romanov Mar 11 at 13:13
add comment

I had the same problem after upgrading to Ubuntu Server 12.04 LTS, running

sudo apt-get install mysql-server 

was enough to fix it, although it complained about an old database of spotweb. I fixed that by removing spotweb:

sudo apt-get purge spotweb

and reconfiguring mysql:

sudo dpkg-reconfigure mysql-server-5.5
share|improve this answer
add comment

This sometimes happens and although there are a couple of different problems that could make mysql not start I will write here some of the most common ones that I know of:

NOTE - Because explaining most common problems I am assuming that you have already tried removing and installing, or simply reinstalling the mysql service as so:

To Install - sudo apt-get install mysql-server mysql-client
To Remove - sudo apt-get remove mysql-server mysql-client
To Purge (Remove files + Config) - sudo apt-get purge mysql-server mysql-client
To Reinstall - sudo apt-get install --reinstall mysql-server mysql-client

  1. my.cnffile is not in the default directory. It should be (By default) be located in either /etc/my.cnf or /etc/mysql/my.cnf.

  2. Not enough space in the hard drive where the mysql data files are located. If the Databases get too big and take 100% of the hard drive, the service will fail.

  3. After upgrade check that the my.cnf file is in the correct place. Depending on how you upgraded or from what version you upgraded from, it could be in /etc/my.cnf or /etc/mysql/my.cnf as mentioned before. Also remember that the file can also be named mysql.conf and not just my.cnf. This happens in cases where you have downloaded the binary from mysql.com.

  4. Doing a dmesg to see what the mysql service is is throwing as an error message helps since it gives the loading error. It might also say why this is happening. If you type dmesg alone in the terminal it will show you the world. What we want is the info about mysql so do something like this: dmesg | grep mysql this will throw you any lines that contain mysql in them.

  5. Check that the my.cnf or mysql.conf file is correct. In 12.04 MySQL is version 5.5, in 11.10 it is version 5.1. It might have some changes in the conf file (Haven't actually checked that) and it might sound silly but it sure can give you some trouble.

  6. Errors related to socket problems normally are the fault of the my.cnf or mysql.conf file pointing to the wrong place, they error will normally show as:

    Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

    The other source of this problem is related to the mysql file in /etc/init.d that it is pointing at the wrong folder because it might be using an older script than the one needed for the actual mysql on the system (It might not have updated correctly, did not overwrite the config file, etc..). So just edit any of this two files and see if they are pointing somewhere else and then simply do a sudo service mysql restart to check if it works.

  7. To have a better look at the error specific outputs of mysql do the following:

    cat /var/log/mysql.err - Will show you the mysql errors. I would make it like this cat /var/log/mysql.err | less if you happen to see too much information fly by since less will help you scroll your way through the output of cat.

    Same goes for cat /var/log/mysql.log If you see the error there maybe putting it in the question or as a comment will help answer this faster.

  8. If you are suffering from connection problems and the service it is actually running, try to see if the Firewall of the server is allowing connections through the 3306 port (Incoming connections). Afterwards check if the router (If it applies) has not blocked port 3306. Basically do a network test to see where the problem related to the port assigned to mysql is originated from.

If all is good, to test if the mysql service is running type service mysql status

As a last resort. If you happen to be running mysql but you can not login try the following:

  1. Stop the MySQL Server:

    sudo /etc/init.d/mysql stop or sudo service mysql stop

  2. Start the mysqld service manually with manual configuration

    sudo mysqld --skip-grant-tables &

    (Remember to add the & else you will have to open another terminal. The & sends the process to the background and you can kill on using the same terminal).

  3. Login to the mysql database as ROOT

    mysql -u root mysql

  4. Type the following replacing the MyPASSWORD with your new password

    UPDATE user SET Password=PASSWORD('MyPASSWORD') WHERE User='root';

This should be enought to login to your Mysql service as root again. Hope it helps.

share|improve this answer
Thanks for prompt feedback. my.cnf file is in /etc/mysql/my.cnf in my case. Is that correct location? dmesg gives me pleeenty of output which is beyond my comprehension :/ I indeed had 5.1 installed - does that have any consequences? –  radek Apr 26 '12 at 23:35
Don't worry about the location if you do find the file. Let me update the answer to provide a better look at the mysql output in dmesg. –  Luis Alvarado Apr 27 '12 at 0:08
add comment

After upgrading I found that mysql-server/mysql-server-5.5 was not installed and neither 5.1. I renamed my.cnf to my.cnf_old and I tried to install mysql-serven. During installation there was an error message that the root password could not be set. After this I checked my configs, apparmor and so on. All seemed to be ok. My next attempt was to reconfigure mysql-server but it complained that the package was not installed completely. So I decided to uninstall and during this apt-get fixed the package and now it is working. I don't know why because I changed nothing.

share|improve this answer
add comment

I had similar problems, but were quickly tracked down to apparmor, which I remembered had given me this issue previously.

If you make changes to these settings and your system uses apparmor, you may also need to also adjust /etc/apparmor.d/usr.sbin.mysqld. Eg. these lines were added (to allow a symlink to the my.cnf, and to allow the symlinked file to be read, presumably):

/usr/sbin/mysqld { ... /etc/mysql/*.cnf lr, /path/to/symlinked/my.cnf r, ... }

share|improve this answer
add comment

In my case it was way easier than some answers here. I found the related bug on launchpad and the fix was as mentioned there in comment 9:

sudo touch /etc/apparmor.d/local/usr.sbin.mysqld
sudo service apparmor restart
share|improve this answer
Thanks. Pity I haven't stumbled upon this one earlier! –  radek Jun 5 '12 at 8:44
add comment

In my case I tried to install MySQL on a fresh installation of Ubuntu 12.04, but I didn't understand why it gave me an error on setting the password for the 'root' user. I tried all the solutions above, but nothing to do.

Then I decided to purge/remove everything, I uninstalled MySQL server and removed all its folders (/etc/mysql/ and /var/lib/mysql/), eventually thank to a sort of randomness it didn't give any error during the reinstallation and I was able to set the password and start the server instance.

share|improve this answer
add comment

In the terminal you can install it again, and makes it run my.cnf you can type:

sudo apt-get install mysql
sudo apt-get update
sudo apt-get --reconfigur mysql
sudo start mysql my.cnf

it might work this way.

share|improve this answer
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. –  waltinator May 6 at 21:52
add comment

protected by Community Jul 29 '12 at 20:09

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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