20

I'm on Kubuntu 12.04, and after installing mysql via an apt-get (mysql ver: 5.5.35), i'm trying to start mysql service, but I got this error:

sudo service mysql start

start: Job failed to start

So I googled this problem, it says i have to go to the /var/log/mysql/error.log

But my error.log file is empty :(

Then I checked the permissions :

drwxr-s--- 2 mysql adm 4096 Apr 7 11:21 mysql

-rw-r----- 1 mysql adm 0 Apr 7 11:21 error.log

So I don't know what to do... Why this error ? Why is the error file empty ?

juergen d
  • 201,996
  • 37
  • 293
  • 362
Alfred
  • 307
  • 1
  • 2
  • 16

13 Answers13

49

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

sudo mkdir /home/<your username>/mysql/
cd /var/lib/mysql/
sudo cp * /home/<your username>/mysql/ -R

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
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.

Rajesh
  • 786
  • 6
  • 12
  • what would be the reason of such a crash ? mysql is pretty stable… It happened to me – Ben Nov 01 '14 at 11:56
  • @Ben :This problem may be occurred due to improper installation or uninstall .If you are installed first time in your system it will not occur . There might be some dependencies that are not properly removed completely when you re-installing mysql. – Rajesh Nov 01 '14 at 12:31
  • I'm very proccupied then.. my mysql install was running for like more than a year, i've upgraded ubuntu then the mysql to 5.5 about a month ago. Never had any problems. Meaning someone made his way into my server you think ? – Ben Nov 01 '14 at 12:33
  • @Ben :After you upgraded ubuntu did you installed mysql once again ? – Rajesh Nov 01 '14 at 12:36
  • I upgraded all the packages (don't remember the command). But not explicitly mysql by itself. My worry is that it had been running like this for more than a month – Ben Nov 01 '14 at 12:46
  • Just do the `sudo apt-get purge mysql-server-5.1 mysql-common` followed by `sudo apt-get install mysql-server` – Nagendra Rao Aug 29 '15 at 06:00
  • 3
    Have people realized that just rebooting might solve this issue? It worked for me and I think it should be the first attempt before performing these steps. – adelriosantiago Oct 30 '15 at 21:28
  • `E: Sub-process /usr/bin/dpkg returned an error code (1)` when `sudo apt-get install mysql-server`. Should have tried rebooting first... – AnnieFromTaiwan Jun 06 '16 at 03:07
  • After I finally solved all the issues and succesfully reinstalled `mysql-server`, I found that my data have all lost!!! The data I have copied via `sudo cp * /home//mysql/ -R` is the same with `/var/lib/mysql/`, which is of no usage. This is a very dangerous and bad answer! – AnnieFromTaiwan Jun 06 '16 at 07:50
  • REMEMBER to use `apt-get update` and `apt-get upgrade` if server not upgraded, because `att-get install mysql-server` will trigg many errors if not consistent... That was my problem. – Peter Krauss Jul 04 '16 at 22:33
  • will my existing databases be safe ? – Ramesh Pareek Jul 15 '17 at 14:51
  • 1
    I had same problem for mysql 5.7 and worked properly too, no databases lost, thanks @Rajesh – surfealokesea Mar 18 '18 at 07:23
10

My problem was running out of memory. Digital ocean has great instruction for adding swap memory for Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

This solved the issue and enabled me to restart the Mysql that otherwise would not start.

blindJustice
  • 235
  • 3
  • 5
6

Reinstallation will works because it will reset all the value to default. It is better to find what the real culprits (my.cnf editing mistake does happens, e.g. bad/outdated parameter suggestion during mysql tuning.)

Here is the mysql diagnosis if you suspect some value is wrong inside my.cnf : Run the mysqld to show you the results.

sudo -u mysql  mysqld 

Afterwards, fix all the my.cnf key error that pop out from the screen until mysqld startup successfully.

Then restart it using

sudo service mysql restart
mootmoot
  • 12,845
  • 5
  • 47
  • 44
5

In my case, it simply because the disk is full. Just clear some disk space and restart and everything is fine.

Orange
  • 349
  • 3
  • 13
3

In most cases, just purging the mysql-server package and re-installing it will do the job.

Run,

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

followed by

sudo apt-get install mysql-server

Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
2

This line did solve the issue in my case,

sudo apt clean
Dileep
  • 128
  • 1
  • 1
  • 11
1

In my case, i do:

  1. sudo nano /etc/mysql/my.cnf
  2. search for bind names and IPs
  3. remove the specific, and let only localhost 127.0.0.1 and the hostname
miken32
  • 42,008
  • 16
  • 111
  • 154
barresoft
  • 11
  • 4
1

Check the file permissions, if edited

Fail:

$ sudo chmod 776 /etc/mysql/my.cnf
$ sudo service mysql restart
mysql stop/waiting
start: Job failed to start

Ok:

$ sudo chmod 774 /etc/mysql/my.cnf
$ sudo service mysql restart
stop: Unknown instance:
mysql start/running, process 9564
ks1bbk
  • 31
  • 2
1

To help others who do not have a full disk to troubleshoot this problem, first inspect your error log (for me the path is given in my /etc/mysql/my.cnf file):

tail /var/log/mysql/error.log

My problem turned out to be a new IP address allocated after some network router reconfiguration, so I needed to change the bind-address variable.

ErichBSchulz
  • 15,047
  • 5
  • 57
  • 61
1

In my case the problem was the /var/log disk full (check with df -h)

Just deleted some log files and mysql started, no big deal!

Tadeu Sampaio
  • 135
  • 1
  • 8
0

The given solution requires enough free HDD, the actual problem was the HDD memory shortage. So If you don't have an alternative server or free disk space, you need some other alternative.

I faced this error with my production server (Linode VPS) when I was running a bulk download into MySQL. Its not a proper solution but VERY QUICK FIX, which we often need in production to bring things UP FAST.

  1. Resize our VPS Server to higher Hard Disk size
  2. Start MySQL, it works.
  3. Login to your MySQL instance and make appropriate adjustments that caused this error (e.g. remove some records, table, or take DB backup to your local machine that are not required at production, etc. After all you know, what caused this issue.)
  4. Downgrade your VPS Server to previous package you was already using
Asif Shahzad
  • 843
  • 2
  • 11
  • 21
0

In my case:

  • restart server
  • restart mysql
  • create .socket in directory
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
Nikolas Soares
  • 479
  • 2
  • 4
  • 13
0

I had the same problem. But i discover that my hd is full.

$ sudo cat /var/log/upstart/mysql.log
/proc/self/fd/9: ERROR: The partition with /var/lib/mysql is too full!

So, I run

$ df -h

And I got the message

/dev/xvda1      7.8G  7.4G     0 100% /

Then I found out which folder was full by running the following command on the terminal

$ cd /var/www
$ for i in *; do echo $i; find $i |wc -l; done

This give me the number of files on each folder on /var/www. I logged into the folder with most files, and deleted some backup files, and i continued deleting useless files and cache files.

then I run $ sudo /etc/init.d/mysql start and it work again

Idealmind
  • 1,278
  • 15
  • 8