How can I overcome this error ?
Error: SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select count(*) as aggregate from
users
where
I'm using Ubuntu
Please help
How can I overcome this error ?
Error: SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select count(*) as aggregate from
users
where
I'm using Ubuntu
Please help
Login as root first:
$ sudo mysql -u root
Then CREATE or ALTER a non-root user (use '127.0.0.1' instead of 'localhost' if needed):
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'adminspassword';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';
FLUSH PRIVILEGES;
Exit and restart:
exit
$sudo service mysql restart
$sudo service apache2 restart
And edit the .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3630
DB_DATABASE=yourdbname
DB_USERNAME=admin
DB_PASSWORD=adminspassword
MySQL will make a difference between "localhost" and "127.0.0.1".
It might be possible that 'root'@'localhost' is not allowed because there is an entry in the user table that will only allow root login from 127.0.0.1.
This could also explain why some application on your server can connect to the database and some not because there are different ways of connecting to the database. And you currently do not allow it through "localhost".
I know its late however looking for answers, I couldn't find anything and at last I got this answer.
$sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
Now you should be able to log in as root. Thanks @Matematikisto in this thread
I encountered this problem in MySQL 8, Ubuntu 20. By default, the policy does not grant "GRANT" rights, including for root, but even after manipulations to obtain them, the application was able to gain access only after granting the mysql_native_password rights to the account. Maybe it will help someone:
UPDATE mysql.user SET authentication_string=CONCAT('*', UPPER(SHA1(UNHEX(SHA1('password'))))), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
the full sequence of steps to change the password and its format is here: MySQL: How to reset or change the MySQL root password?