Solve "Access denied for user 'root'@'localhost'"

avatar

Haikel, 1 min read / October 23, 2022

بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ

When i was working with Prisma, i got an error like this:

access denied mysql

So yeah, i just search the solution on google. And found the solution on Stackoverflow

sudo mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
sudo service mysql restart
solution

Btw, the syntax in Mysql isn't case sensitive, so if you type the syntax in lowercase or uppercase, it's fine.

If you want to check the port of your Mysql, you can check it like this(make sure that you've start your Mysql):

SHOW GLOBAL VARIABLES LIKE 'PORT';
check mysql port