If you’ve recently upgraded to Ubuntu 16.04 or newer with MySQL 5.7+, you might have encountered an unexpected authentication error when trying to access phpMyAdmin with your root credentials.
The familiar error message #1698 - Access denied for user 'root'@'localhost' can be frustrating, especially when you’re certain your credentials are correct.
I experienced this firsthand after upgrading my development environment from Ubuntu 15.10 to 16.04. What seemed like a routine upgrade quickly turned into a troubleshooting session as my previously working phpMyAdmin setup suddenly refused to accept my root login.
In this guide, I’ll walk you through why this happens and provide multiple solutions to fix the authentication problem, ensuring you can regain access to your databases through phpMyAdmin.
MySQL 5.7 introduced a significant security model change that affects how the root user authenticates. In previous versions, you could simply use a username and password combination. However, in MySQL 5.7 and later:
auth_socket plugin by defaultThis security enhancement improves your server’s protection but creates complications for tools like phpMyAdmin that don’t have sudo capabilities.
Read: How to Install MySQL Workbench on Ubuntu 22.04
The safest and most sustainable solution is to create a dedicated user for phpMyAdmin with appropriate privileges. This approach:
sudo mysql --user=root mysql
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Security Note: Replace ‘your_strong_password’ with a secure password. Never use the example passwords from tutorials in production environments!
sudo nano /etc/dbconfig-common/phpmyadmin.conf
Update the user and password sections:
# dbc_dbuser: database user
dbc_dbuser='phpmyadmin'
# dbc_dbpass: database user password
dbc_dbpass='your_strong_password'
sudo service apache2 restart
sudo service mysql restart
http://localhost/phpmyadmin and log in with your new credentials: Read: How to change MySQL root password
If you prefer to continue using the root user with phpMyAdmin (generally not recommended for production servers), you can change the authentication plugin:
sudo mysql --user=root
SELECT User, Host, plugin FROM mysql.user WHERE User = 'root';
You’ll likely see auth_socket as the plugin for root.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_root_password';
FLUSH PRIVILEGES;
exit;
Warning: This change will need to be reapplied after MySQL updates, as they often reset the authentication method.
If you’re still having issues, reconfiguring phpMyAdmin might help:
sudo dpkg-reconfigure phpmyadmin
Follow the interactive prompts:
If you can log in but cannot create new databases, you might need additional privileges:
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MySQL updates may reset your authentication settings. After updates, you might need to:
The authentication changes in MySQL 5.7+ enhance security but require adjustments to how you interact with phpMyAdmin. By creating a dedicated phpMyAdmin user or modifying the authentication method, you can regain access to your database management interface while maintaining appropriate security levels.
Remember that the most secure approach is to create dedicated database users with appropriate privileges rather than using the root account for everyday tasks. This practice not only improves security but also provides better audit trails and makes your system more resilient to updates.
The change to auth_socket plugin for root authentication was implemented as a security enhancement to prevent brute force attacks against the root user and to ensure that only local system administrators with sudo privileges could access the root MySQL account.
Changes to the authentication method for the root user may be reset during MySQL updates. The dedicated user approach (Solution 1) is more likely to persist across updates.
Yes, most of these solutions also work for MariaDB, as it follows similar authentication principles. The specific commands may vary slightly depending on the MariaDB version.
For development environments, it’s generally acceptable. For production servers, you should consider granting only the specific privileges needed for your applications.
Run the following command to check user authentication methods:
SELECT User, Host, plugin FROM mysql.user;
You can reset it by connecting to MySQL as root and running:
ALTER USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;
The post How to Fix phpMyAdmin Login Issues with MySQL 5.7 on Ubuntu appeared first on net2.
Previously I have written about how useful public cloud storage can be when starting a…
This is Part 2 of the "Karafka to Async Journey" series. Part 1 covered WaterDrop's…
For many software teams, documentation is written after features are built and design decisions have…
With the release of the FIPS 140-3 certified cryptographic modules for Ubuntu 22.04 LTS, Canonical…
Open source libraries are repositories of code that developers can use and, depending on the…
Last year, we had the opportunity to speak at Regent’s UX Conference (Regent’s University London’s…