I bought a VPS today to use as my new MySQL server. I installed MySQL, Apache, PHP, and phpMyAdmin. I set up my MySQL user as "admin". I am able to log into the user on the command-line, but not in phpMyAdmin. I get the error #1251 Cannot log in to the MySQL server
.
The issue is on a new Linux VPS running CentOS 6, MySQL 8.0.16, and Apache 2.2.15. I have tried everything I came across in the past 6 hours of googling. I will create a list of everything I've tried since that will be easier to read.
- setting bind-address to 127.0.0.1
- putting my username and password into config.inc.php
- setting the host to 127.0.0.1 in config.inc.php
- trying sockets over TCP (and setting the host to localhost when using sockets)
- creating a soft-link shortcut from `/usr/share/phpmyadmin` to `/var/www/html/phpmyadmin`
- reinstalling and running mysql_secure_installation
and a lot more things that I can't quite recall at the moment.
config.inc.php
$cfg['Servers'][$i]['host'] = '127.0.0.1'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ''; // MySQL port - leave blank for default port
$cfg['Servers'][$i]['socket'] = ''; // Path to the socket - leave blank for default socket
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
$cfg['Servers'][$i]['extension'] = 'mysqli'; // The php MySQL extension to use ('mysql' or 'mysqli')
$cfg['Servers'][$i]['compress'] = FALSE; // Use compressed protocol for the MySQL connection
// (requires PHP >= 4.3.0)
$cfg['Servers'][$i]['controluser'] = ''; // MySQL control user settings
// (this user must have read-only
$cfg['Servers'][$i]['controlpass'] = ''; // access to the "mysql/user"
// and "mysql/db" tables).
// The controluser is also
// used for all relational
// features (pmadb)
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user'] = 'admin'; // MySQL user
$cfg['Servers'][$i]['password'] = 'areallygoodpassword'; // MySQL password (only needed
httpd.conf
<IfModule php5_module>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
LoadModule php5_module modules/libphp5.so
AddType x-httpd-php .php
AddHandler php5-script .php
phpMyAdmin.conf
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
Order Allow,Deny
Allow from All
</Directory>
my.cnf
bind-address=127.0.0.1
After trying all of this, I have had no luck and I am still getting the same error #1251 Cannot log in to the MySQL server
. Any help would be greatly appreciated at this point, as I am getting desperate.
EDIT: The issue was my user's passwords were saved as caching_sha2_password instead of mysql_native_password. See the answer below.
First, try by disabling the SELinux by using the command
setenforce 0
check user, host and password plugin by using query through MySQL prompt.
SELECT user, host, plugin from mysql.user
plugin must be set to "mysql_native_password, and the host should be localhost. if it is not you can update your plugin by:
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'admin'
and update host:
UPDATE mysql.user SET host = 'localhost' WHERE User = 'admin'