Software & AppsOperating SystemLinux

How To Fix “Access denied for user ‘root’@’localhost’ error” in Adminer.php on Ubuntu 18.04

Ubuntu 9

In this article, we will explore how to resolve the “Access denied for user ‘root’@’localhost'” error that can occur when using Adminer.php on Ubuntu 18.04. This error often arises due to incorrect user privileges or authentication issues with the MySQL database.

Understanding the Error

Before we dive into the solutions, it’s crucial to understand the error. The “Access denied for user ‘root’@’localhost'” error message indicates that the MySQL database is not allowing the root user to connect from the localhost. This issue can arise due to various reasons, such as incorrect user credentials, wrong database configuration, or issues with the MySQL service itself.

Solution 1: Check the Status of httpd_read_user_content

The first solution involves checking the status of httpd_read_user_content. This is a Boolean setting in SELinux that controls whether the Apache HTTP server can read user content.

Steps:

  1. Open a terminal with root user privileges using the command sudo -i.
  2. Run the command getsebool -a | grep http. This command fetches all the SELinux booleans related to HTTP and filters out the httpd_read_user_content status.
  3. If httpd_read_user_content is set to “off”, run the command setsebool -P httpd_read_user_content on to enable it. The -P option makes the change persistent across reboots.
  4. Restart the Apache server using the command systemctl restart apache2.
  5. Try accessing Adminer.php again.

Solution 2: Create a New User with Administrative Privileges

In newer versions of MariaDB/MySQL, the default root user authentication method on Linux is unix socket, which means only the root user itself can log in without a password. To use Adminer.php, it is recommended to create a new root-like user with a password.

Steps:

  1. Open a terminal and log in to MySQL as the root user with the command mysql -u root -p. Enter your root password when prompted.
  2. Create a new user with the command CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';. Replace ‘newuser’ and ‘password’ with your desired username and strong password.
  3. Grant all privileges to the new user with the command GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';.
  4. Flush the privileges to ensure they are saved and reloaded by the server using the command FLUSH PRIVILEGES;.
  5. Exit MySQL with the command exit.
  6. Update the configuration files of Adminer.php to use the newly created user’s credentials.
  7. Retry accessing Adminer.php with the new user’s credentials.

Conclusion

By following the above solutions, you should be able to resolve the “Access denied for user ‘root’@’localhost'” error in Adminer.php on Ubuntu 18.04. Remember to always use strong passwords and follow best practices for user management to secure your database. If you continue to experience issues, consider reaching out to the Ubuntu or Adminer.php communities for further assistance.

What is Adminer.php?

Adminer.php is a single-file database management tool written in PHP. It allows you to easily manage and interact with databases, including MySQL, MariaDB, PostgreSQL, SQLite, and more, through a web interface.

Can I use Adminer.php to manage remote databases?

Yes, you can use Adminer.php to manage remote databases. When accessing Adminer.php, instead of using localhost in the database connection settings, you need to enter the hostname or IP address of the remote server where the database is located. Make sure that the remote server allows remote connections and that you have the necessary credentials to access the database remotely.

Can I connect to databases other than MySQL with Adminer.php?

Yes, Adminer.php supports various database systems, including MySQL, MariaDB, PostgreSQL, SQLite, Oracle, MS SQL, and more. When accessing Adminer.php, you can select the desired database system from the dropdown menu and provide the appropriate connection details for that specific database system.

Leave a Comment

Your email address will not be published. Required fields are marked *