Home > Database > Mysql Tutorial > body text

How to Fix \'SQLSTATE[HY000] [1698] Access denied for user \'root\'@\'localhost\'\' Error in Ubuntu 16.04?

Patricia Arquette
Release: 2024-11-01 12:11:29
Original
895 people have browsed it

How to Fix

Troubleshooting "SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'" Error in Ubuntu 16.04

Introduction:

When attempting to access a MySQL database from PHP or phpMyAdmin, you may encounter the following error:

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
Copy after login

This error indicates that the user attempting to connect to the database lacks the necessary privileges.

Solution:

A recent change in MySQL 5.7 prevents the root user from connecting to the database without elevated privileges. To resolve this issue, follow these steps:

  1. Create a New User with Privileges:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' WITH GRANT OPTION;
Copy after login
  1. Update Your PHP Code:

Modify the PHP code to connect using the new user credentials:

<code class="php">protected $name = 'newuser';
protected $pass = 'password';</code>
Copy after login
  1. Connect Using Sudo:

If you wish to continue using the root user, you will need to elevate your privileges by running commands with sudo:

<code class="sh">sudo mysql -u root</code>
Copy after login

Additional Considerations:

  • Ensure that the new user has the required privileges for the database operations you intend to perform.
  • If you encounter any further issues, consult the MySQL documentation or seek support from the MySQL community.

The above is the detailed content of How to Fix \'SQLSTATE[HY000] [1698] Access denied for user \'root\'@\'localhost\'\' Error in Ubuntu 16.04?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!