A confusing point for almost everyone who starts using mysql is that 'root' and 'root@localhost' are two different roles and as such could (and some would argue that they actually should) have different passwords. It is quite possible you are trying to log-in as user 'root@localhost' and you are providing the password for 'root' role.
If this is the case, you can remedy it quite easily. Log-in to the database server using the CLI tool mysql as user root like this:
mysql --user=root --password
The tool will ask for your root password (not system root but database root). Now you can modify the password of 'root'@'localhost' like this:
UPDATE mysql.user SET Password=PASSWORD('cleartext password')
WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;
Now try to log-in through phpMyAdmin using the newly set password.
You can recover or set root password without knowing the current one by starting mysql without loading the grant-tables.
Please note the $
in the commands. This is specifying the terminal prompt you see when typing in the command. It's showing it's a line of text, but and actual typed terminal command. The "mysql>
" prefix is also a prompt. That is the prompt you get when running mysql interactivately.
This is the cli (command line) to do this:
(Be sure to stop the current server before performing the steps. Only one server can run at a time.)
$ sudo mkdir /var/run/mysqld; sudo chown mysql /var/run/mysqld
$ sudo mysqld_safe --skip-grant-tables&
Now you can log in as root without a password and perform all commands, as in this case, set the root password as root.
$ sudo mysql --user=root mysql
This is the set root password that you will perform inside mysql if you have MySQL 5.6 or below:
mysql> update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
In MySQL 5.7 or above
mysql> update user set authentication_string=PASSWORD('new-password') where user='root';
flush privileges;
From there, quit (kill the running msqld) mysql and start it as normal.
Notes on starting and stopping the mysql service:
Stop mysql:
$ sudo service mysql stop
Start mysql (normal):
$ sudo service mysql start
Kill the temporary mysql safe mode session:
$ sudo mysqladmin shutdown
Best Answer
You can change the mysql root password by logging in to the database directly (
mysql -h your_host -u root
) then runphpmyadmin should use that password so not quite sure what you mean by "for both".
Make sure to set the new password into phpmyadmin's
Otherwise, phpmyadmin may not work, echoingconfig.inc.php
too, at line