Choose from one of the two following methods:
Method 1: Create a New Superuser for phpMyAdmin
Method 2: Change root Authentication Method
In terminal, log in to MySQL as root
. You may have created a root password when you installed MySQL for the first time or the password could be blank. If you have forgotten your root password, you can always Reset the MySQL Root Password.
1 |
sudo mysql -p -u root |
Now add a new MySQL user with the username of your choice. In this example we are calling it pmauser
. Make sure to replace password_here
with your own. You can generate a strong password here.
The command below will create a new user called pmauser
(call this what you like) which can access the MySQL server from localhost
with the password password_here
.
1 |
CREATE USER 'pmauser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password_here'; |
Now we will grant superuser privilege to our new user pmauser
.
1 |
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost'; |
You should now be able to access phpMyAdmin using this new user account.
If you are getting an error for this new user “Access denied for user (using password: YES)”, please read this article.
If you are getting an error “Failed to set session cookie. Maybe you are using HTTP instead of HTTPS”, please read this article.
In order to log into phpMyAdmin as your root MySQL user, you will need to switch its authentication method from auth_socket
or caching_sha2_password
to mysql_native_password
.
Open up the MySQL prompt from your terminal:
1 |
sudo mysql |
Run the following query.
1 |
SELECT user,plugin,host FROM mysql.user WHERE user = 'root'; |
Output:
1 2 3 4 5 6 7 |
+------+-------------+-----------+ | user | plugin | host | +------+-------------+-----------+ | root | <span class="red">auth_socket</span> | localhost | +------+-------------+-----------+ 1 row in set (0.00 sec) |
Above we can see that the plugin for the root account is set to auth_socket
. This may also say caching_sha2_password
. You need to change this to mysql_native_password
. Also, the host value should be set to localhost
or %
. If it’s set to anything else, you may not be able to log into phpMyAdmin with root. See: Understanding MySQL Users and Hosts
Run the following query to change the plugin value to mysql_native_password
. Make sure to replace enter_password_here
with your own. Click here if you need to generate a new password.
1 |
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'enter_password_here'; |
Flush privileges.
1 |
FLUSH PRIVILEGES; |
You should now be able to log into phpMyAdmin using your root account.
ที่มา : https://devanswers.co/phpmyadmin-access-denied-for-user-root-localhost/
ป้ายกำกับ:access denied, localhost, mysql, phpmyadmin, root