Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to reset the root password of my local mysql installation but it woudln't let me. I've tried this:

$ sudo /etc/init.d/mysql stop
 * Stopping MySQL database server mysqld                                                                                                              [ OK ] 
[1]-  Exit 1                  sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking
[2]+  Exit 1                  sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking
reg@regDesktopHome:~$ sudo mysqld --skip-grant-tables &
[1] 13651
reg@regDesktopHome:~$ 140627 19:02:02 [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.

reg@regDesktopHome:~$ mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
reg@regDesktopHome:~$ sudo mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[1]+  Exit 1                  sudo mysqld --skip-grant-tables

How can I get the password reset? edit 1 I got this:

$ ps ax| grep mysql
16515 ?        Ssl    0:00 /usr/sbin/mysqld
16551 pts/23   S+     0:00 grep --color=auto mysql
reg@regDesktopHome:~/semios/v3upgrade$ sudo kill -9 16515
reg@regDesktopHome:~/semios/v3upgrade$ ps ax| grep mysql
16678 ?        Ssl    0:00 /usr/sbin/mysqld
16715 pts/23   S+     0:00 grep --color=auto mysql
reg@regDesktopHome:~/semios/v3upgrade$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

looks like a process is automatically restarting mysql as soon as I kill it...

share|improve this question
up vote 35 down vote accepted

First please try using

mysql -u root -p

and enter your password (if you remember) at the prompt to login as the sql-root user (note the switch -p is for password).

If you really have to reset your root password for mysql, here's an easy way - reconfigure the package with dpkg-reconfigure.

Easy steps to reset mySQL root password:

  1. Check the version of your mysql-server;

    apt-cache policy mysql-server

    and see for the line which shows the installed version among other information. e.g. for my install it's:

       Installed: 5.5.37-0ubuntu0.12.04.1

    (From this I know that I have mysql-server-5.5 installed in my system.)

  2. Start the reconfiguration with:

    sudo dpkg-reconfigure mysql-server-*.*

    where mysql-server-*.* should be replaced by the version that you have. (for me it'd be mysql-server-5.5). This will stop the database daemon. A prompt will then appear where you'd have to enter your new password and confirm the reconfiguration.


    The daemon will be automatically started after the reconfig completes.

  3. You can then log in with:

    mysql -u root -p

    and start your database admin tasks.


  1. [Which would soon be cleaned up as indicated in the page.]

  2. Ubuntu Server Guide related to your specific version, available at: Select your Ubuntu version and click on Ubuntu Server Guide and look for the database help page.

share|improve this answer
Can confirm that dpkg-reconfigure mariadb-server-10.1 worked for MariaDB when all other solutions didn't. Thank you for this. – liviucmg Oct 3 '14 at 21:49
Yes this worked - better to understand what is going on - Thanks rusty – Gadgetroid Nov 5 '14 at 9:56
Didn't work for me on 14.04LTS. What worked was: dpkg-reconfigure mysql-server-5.5 – Dec 29 '14 at 1:22
dpkg-reconfigure didn't prompt for password for me.. is there a way to force it? – Unirgy Dec 17 '15 at 18:02

Reference taken from this blog:

Step 1: Stop MySQL Service.

sudo service mysql stop

Step 2: Kill all running mysqld.

sudo killall -9 mysqld

Step 3: Starting mysqld in Safe mode.

sudo mysqld_safe --skip-grant-tables --skip-networking &

Step 4: Start mysql client

mysql -u root

Step 5: After successful login, please execute this command to change any password.


Step 6: You can update mysql root password .

UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';

Step 7: Please execute this command.


Step 8: Exit mysql console


Step 9: Kill mysqld_safe and start mysql

sudo killall mysqld_safe && sudo service mysql start
share|improve this answer
should be sudo service mysql stop, not sudo stop mysql – knocte Jul 4 at 3:51
also, at the end it's missing the steps sudo killall mysqld_safe && sudo service mysql start and then try to log in again – knocte Jul 4 at 3:58
For MYSQL 5.7 the change password syntax has changed to ALTER USER root IDENTIFIED BY 'NEW_PASSWORD_HERE' – Tarek Fadel Jul 6 at 7:55

Create a file with this:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';

Stop the mysql server and run this:

mysqld_safe --init-file=/home/me/mysql-init &

Check here for more details:

share|improve this answer

Your Answer


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.