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
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.
- Open a terminal with root user privileges using the command
- Run the command
getsebool -a | grep http. This command fetches all the SELinux booleans related to HTTP and filters out the
httpd_read_user_contentis set to “off”, run the command
setsebool -P httpd_read_user_content onto enable it. The
-Poption makes the change persistent across reboots.
- Restart the Apache server using the command
systemctl restart apache2.
- 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.
- 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.
- 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.
- Grant all privileges to the new user with the command
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';.
- Flush the privileges to ensure they are saved and reloaded by the server using the command
- Exit MySQL with the command
- Update the configuration files of Adminer.php to use the newly created user’s credentials.
- Retry accessing Adminer.php with the new user’s credentials.
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.
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.
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.
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.