34

I recently installed LAMP on Ubuntu 13.04(32-bit) but forgot my phpMyAdmin password. How can I reset its password without re-installing it?

Seth
  • 57,282
  • 43
  • 144
  • 200
tHe_VaGaBonD
  • 493
  • 3
  • 6
  • 11
  • For people having issues with the current accepted answer. I suggest checking out the DigitalOcean article [How To Reset Your MySQL or MariaDB Root Password](https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password) – 3limin4t0r Nov 10 '22 at 11:45

4 Answers4

44

Simply change or reset your MySQL root password by doing the following:

  1. Stop the MySQL server

    sudo service mysql stop
    
  2. Start mysqld

    sudo mysqld --skip-grant-tables &
    
  3. Login to MySQL as root

    mysql -u root mysql
    
  4. Change MYSECRET with your new root password

    UPDATE user SET Password=PASSWORD('MYSECRET') WHERE User='root'; FLUSH PRIVILEGES; exit;
    
  5. Kill mysqld

    sudo pkill mysqld
    
  6. Start mysql

    sudo service mysql start
    
  7. Login to phpmyadmin as root with your new password

Seth
  • 57,282
  • 43
  • 144
  • 200
jctoledo
  • 1,559
  • 13
  • 8
  • Can you please explain the use of #2 Start mysqld? Also, how will I be able to execute #3 since I don't remember my MySQL password anymore? – tHe_VaGaBonD Jul 22 '13 at 16:40
  • 1
    The idea for #2 is that you are spawning a version of the MySQL daemon *without* a password. This allows you to reset it on step 4. – jctoledo Aug 06 '13 at 15:54
  • Using Ubuntu 16 I was not able to run mysqld manually - trying to create socket and socket lock file in a dir that didn't even exist! But if you look at the very NEXT answer (which is not the accepted answer) that is what I needed - I stupidly forgot the password for the phpmyadmin user, and there it is, in plain text, in the phpmyadmin.conf folder! – Brian B Sep 06 '17 at 18:09
  • ERROR 1054 (42S22): Unknown column 'Password' in 'field list' – Tiago Gouvêa Dec 26 '18 at 17:04
  • I get `2020-09-22 10:40:17 140163612645568 [Note] mysqld (mysqld 10.2.14-MariaDB) starting as process 23841 ... mysqld: Please consult the Knowledge Base to find out how to run mysqld as root! 2020-09-22 10:40:17 140163612645568 [ERROR] Aborting ` at step **2** – Black Sep 22 '20 at 08:40
  • You might want to use the command `sudo mysqld --skip-grant-tables --user=root &` for the second step, as stated [in this answer](https://stackoverflow.com/a/60559556/4215651). – MAChitgarha Jul 13 '21 at 18:43
  • Also, for newer versions of MySQL, or if you're encountering errors relating to the password field (i.e. syntax errors), you should try `UPDATE mysql.user SET authentication_string=null WHERE User='root'; FLUSH PRIVILAGES; exit;` for the third step. See [this answer](https://stackoverflow.com/a/63716361/4215651). – MAChitgarha Jul 13 '21 at 19:08
38

You don't actually need to reset your username and password, if you can see them.

In your terminal window, type:

sudo -H gedit /etc/dbconfig-common/phpmyadmin.conf

This will open your phpmyadmin configurations.

There, you will see your username under dbc_dbuser='your_username' and password under dbc_dbpass='your_password'.

muru
  • 193,181
  • 53
  • 473
  • 722
lordparthurnaax
  • 618
  • 9
  • 21
9

There is a workaround on Debian (Ubuntu, Mint, etc.) where there is a second admin account automatically generated by the system called

debian-sys-maint

You can see (and should not change) its password via

sudo nano /etc/mysql/debian.cnf

It is possible (sure on Ubuntu 16.04) to use that account both in phpMyAdmin as well as in the command line

mysql -u debian-sys-maint -p

The account has exactly the same privileges as phpMyAdmin's / MySQL's root.

Kulfy
  • 17,416
  • 26
  • 64
  • 103
Petr Kosvanec
  • 93
  • 1
  • 5
0

I was wondering why my login was failing even though I never changed the password.

It was failing because I rebootet the server and the mysql server was not startet automatically. So I startet the server and it worked again.

Black
  • 774
  • 1
  • 7
  • 16