1

I've installed mysql-server on a Linux box and forgot (oops) the root password. Having looked around the internet, the general method is so:

  1. Stop MySQL (sudo service mysql stop)
  2. Start MySQL in special mode (sudo mysqld_safe --skip-grant-tables)
  3. Login to local server and reset password (mysql -u root)

My problem is at number 2. When I run the command, it says some stuff about logging and starting the daemon, then ends with the line

mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

and using sudo service mysql status confirms that MySQL has, indeed stopped.

Why does it stop so suddenly? And (more importantly) how can I get it to keep running so I can reset my password?

Thanks in advance

EDIT Here's the full log of "stuff about loggin and starting the daemon":

$ mysqld_safe --skip-grant-tables 
141219 16:55:20 mysqld_safe Logging to syslog.
141219 16:55:20 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
141219 16:55:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
$ 

EDIT 2 And the output of /var/log/syslog (I've replaced my hostname with <hostname>)

Dec 20 10:20:09 <hostname> mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql
Dec 20 10:20:09 <hostname> mysqld: 141220 10:20:09 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
Dec 20 10:20:09 <hostname> mysqld: 141220 10:20:09 [Warning] Can't create test file /var/lib/mysql/<hostname>.lower-test
Dec 20 10:20:09 <hostname> mysqld: 141220 10:20:09 [Warning] Can't create test file /var/lib/mysql/<hostname>.lower-test
Dec 20 10:20:09 <hostname> mysqld: #007/usr/sbin/mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13)
Dec 20 10:20:09 <hostname> mysqld: 141220 10:20:09 [ERROR] Aborting
Dec 20 10:20:09 <hostname> mysqld: 
Dec 20 10:20:09 <hostname> mysqld: 141220 10:20:09 [Note] /usr/sbin/mysqld: Shutdown complete
Dec 20 10:20:09 <hostname> mysqld: 
Dec 20 10:20:09 <hostname> mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
5
  • Please can you add all of the "stuff about logging and starting the daemon" to the question. It's not possible to diagnose a problem if you edit out all of the diagnostic information.
    – Mike Scott
    Dec 19, 2014 at 16:30
  • OK, thanks for that data. Now can you look in syslog to see what it's logged there?
    – Mike Scott
    Dec 19, 2014 at 17:59
  • Where do I access syslog?
    – Luke Moll
    Dec 19, 2014 at 20:21
  • I'm afraid that depends on how you've configured your system, but you could look for /var/syslog.
    – Mike Scott
    Dec 19, 2014 at 21:11
  • It was in /var/log/syslog, I've re-run the command to get the output as it looks like syslog only keeps the most recent messages.
    – Luke Moll
    Dec 20, 2014 at 10:30

4 Answers 4

0

OK, it looks like either /var/lib/mysql doesn't exist or the mysql user doesn't have permission to access it. Either way, you have worse problems than having forgotten the root password -- either you don't have a database at all, or something has changed the file permissions or ownership.

3
  • Would reinstalling mysql-server help?
    – Luke Moll
    Dec 20, 2014 at 17:41
  • Probably, yes, if you don't have any data that you want to keep.
    – Mike Scott
    Dec 20, 2014 at 18:45
  • No idea what the problem was, but ran #apt-get purge mysql-server mysql-server-5.5 mysql-core-5.5 and then reinstalled MySQL server (making sure to write down the password :D)
    – Luke Moll
    Dec 23, 2014 at 23:36
5

This issue might be caused due to several issue. You can find the exact error from "tail /var/log/mysql/error.log". I have added the default fix for these kind of issues. If the below is not working then update us the print from log where we can try to get some info and move further

Kill all the MySQL process using the following command.

ps aux | grep mysql kill pid

Find the path of mysqld daemon using the "which mysqld_safe" command

Start MySQL without grant tables from the mysqld_safe location

/mysqld_safe_available_directory/mysqld_safe --skip-grant-tables &

ex /bin/mysqld_safe

mysql -u root 

Steps to set the new password:

use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit
1
  • Gave it a try but $ ps aux | grep mysql kill pid gives grep: kill: No such file or directory grep: pid: No such file or directory, then rest of steps same problem as question (... pid ended). When I tried just ps aux | grep mysql then kill (pid) where pid it the number in the pid column, it says No such process.
    – Luke Moll
    Dec 19, 2014 at 16:50
0

I faced same problem Aborting come from permission on /var/lib/mysql the folder belong to user mysql, then root has no fully access

solved it by:

$ sudo su - mysql

$ mysqld_safe --skip-grant-tables &
0

In my case I was manually created the /var/run/mysql folders with root user. Solved issuing

chown -R mysql:mysql /var/run/mysql

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .