mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost' code example
Example 1: Illuminate\Database\QueryException : SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
$ sudo mysql -u root -p
Now you can add a new MySQL user with the username of your choice.
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
And finally grant superuser privileges to the user you just created.
mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
after that go and edit .env DB_USERNAME=newuser
DB_PASSWORD=password
Example 2: Got error: 1698: Access denied for user 'root'@'localhost' when trying to connect
$ sudo mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
$ service mysql restart
Example 3: access denied for user 'root'@'localhost' python sql-connect error
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password';
FLUSH PRIVILEGES;
Example 4: mysqli::real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)
$cfg['Servers'][$i]['port'] = '3307';
Example 5: mysqli_real_connect(): (HY000/1698): Access denied for user 'root'@'localhost'
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';