Error #1251 - Cannot log in to the MySQL server - php

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'

Related

How to enable federated engine in mysql? Missing my.cnf file

I have found multiple solutions on stackoverflow, however none seemed to work as I don't have the my.cnf file, (except under the mysql folder I have one, but it doesnt have [mysqld] section.) Not really sure what else to check.
I just purchased a server. I have installed,
-apache
-mysql
-php
-phpmyadmin
all on Ubuntu 20.10 x64
Trying to create a link between this server and another server.
I was able to find it myself. It is under the folder:
/etc/mysql/mysql.conf.d
File Name: mysqld.cnf
I then proceeded with adding federated to the below info:
[mysqld]
#
# * Basic Settings
#
user = mysql
# pid-file = /var/run/mysqld/mysqld.pid
# socket = /var/run/mysqld/mysqld.sock
# port = 3306
# datadir = /var/lib/mysql
federated

Connect to remote localhost DB [duplicate]

Assuming there is a remote server and I have phpMyAdmin client installed localy on my computer. How can I access this server and manage it via phpMyAdmin client? Is that possible?
Just add below lines to your /etc/phpmyadmin/config.inc.php file in the bottom:
$i++;
$cfg['Servers'][$i]['host'] = 'HostName:port'; //provide hostname and port if other than default
$cfg['Servers'][$i]['user'] = 'userName'; //user name for your remote server
$cfg['Servers'][$i]['password'] = 'Password'; //password
$cfg['Servers'][$i]['auth_type'] = 'config'; // keep it as config
You will get Current Server: drop down with both 127.0.0.1 and one what you have provided with $cfg['Servers'][$i]['host'] can switch between the servers.
More Details: http://sforsuresh.in/access-remote-mysql-server-using-local-phpmyadmin/
It is certainly possible to access a remote MySQL server from a local instance of phpMyAdmin, as the other answers have pointed out. And for that to work, you have to configure the remote server's MySQL server to accept remote connections, and allow traffic through the firewall for the port number that MySQL is listening to. I prefer a slightly different solution involving SSH Tunnelling.
The following command will set up an SSH tunnel which will forward all requests made to port 3307 from your local machine to port 3306 on the remote machine:
ssh -NL 3307:localhost:3306 root#REMOTE_HOST
When prompted, you should enter the password for the root user on the remote machine. This will open the tunnel. If you want to run this in the background, you'll need to add the -f argument, and set up Passwordless SSH between your local machine and the remote machine.
After you've got the SSH tunnel working, you can add the remote server to the servers list in your local phpMyAdmin by modifying the /etc/phpmyadmin/config.inc.php file. Add the following to the end of the file:
$cfg['Servers'][$i]['verbose'] = 'Remote Server 1'; // Change this to whatever you like.
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3307';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['compress'] = FALSE;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$i++;
I wrote a more in-depth blog post about exactly this, in case you need additional help.
It can be done, but you need to change the phpMyAdmin configuration, read this post:
http://www.danielmois.com/article/Manage_remote_databases_from_localhost_with_phpMyAdmin
If for any reason the link dies, you can use the following steps:
Find phpMyAdmin's configuration file, called config.inc.php
Find the $cfg['Servers'][$i]['host'] variable, and set it to the IP or hostname of your remote server
Find the $cfg['Servers'][$i]['port'] variable, and set it to the remote mysql port. Usually this is 3306
Find the $cfg['Servers'][$i]['user'] and $cfg['Servers'][$i]['password'] variables and set these to your username and password for the remote server
Without proper server configuration, the connection may be slower than a local connection for example, it's would probably be slightly faster to use IP addresses instead of host names to avoid the server having to look up the IP address from the hostname.
In addition, remember that your remote database's username and password is stored in plain text when you connect like this, so you should take steps to ensure that no one can access this config file. Alternatively, you can leave the username and password variables empty to be prompted to enter them each time you log in, which is a lot more secure.
Follow this blog post. You can do it very easily.
https://wadsashika.wordpress.com/2015/01/06/manage-remote-mysql-database-locally-using-phpmyadmin/
The file config.inc.php contains the configuration settings for your phpMyAdmin installation. It uses an array to store sets of config options for every server it can connect to and by default there is only one, your own machine, or localhost. In order to connect to another server, you would have to add another set of config options to the config array. You have to edit this configuration file.
First open config.inc.php file held in phpMyAdmin folder. In wamp server, you can find it in wamp\apps\phpmyadmin folder. Then add following part to that file.
$i++;
$cfg['Servers'][$i]['host'] = 'hostname/Ip Adress';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['compress'] = FALSE;
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'username';
$cfg['Servers'][$i]['password'] = 'password';
Let’s see what is the meaning of this variables.
$i++ :- Incrementing variable for each server
$cfg[‘Servers’][$i][‘host’] :- Server host name or IP adress
$cfg[‘Servers’][$i][‘port’] :- MySQL port (Leave a blank for default port. Default MySQL port is 3306)
$cfg[‘Servers’][$i][‘socket’] :- Path to the socket (Leave a blank for default socket)
$cfg[‘Servers’][$i][‘connect_type’] :- How to connect to MySQL server (‘tcp’ or ‘socket’)
$cfg[‘Servers’][$i][‘extension’] :- php MySQL extension to use (‘mysql’ or ‘msqli’)
$cfg[‘Servers’][$i][‘compress’] :- Use compressed protocol for the MySQL connection (requires PHP >= 4.3.0)
$cfg[‘Servers’][$i][‘auth_type’] :- Method of Authentication
$cfg[‘Servers’][$i][‘username’] :- Username to the MySQL database in remote server
$cfg[‘Servers’][$i][‘password’] :- Password to the MySQL database int he remote server
After adding this configuration part, restart you server and now your phpMyAdmin home page will change and it will show a field to select the server.
Now you can select you server and access your remote database by entering username and password for that database.
As stated in answer c.hill answer, if you want a secure solution I would advise to open an SSH tunnel to your server.
Here is the way to do it for Windows users:
Download Plink and Putty from the Putty website and place the files in the folder of your choice (In my example C:\Putty)
Open the Windows console and cd to Plink folder:
cd C:\Putty
Open the SSH tunnel and redirect to the port 3307:
plink -L 3307:localhost:3306 username#server_ip -i path_to_your_private_key.ppk
Where:
3307 is the local port you want to redirect to
localhost is the address of the MySQL DB on the remote server (localhost by default)
3306 is the port use for PhpMyAdmin on the remote server (3306 by default)
Finally you can setup PhpMyAdmin:
Add the remote server to your local PhpMyAdmin configuration by adding the following line at the end of config.inc.php
Lines to add:
$i++;
$cfg['Servers'][$i]['verbose'] = 'Remote Dev server';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '3307';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['compress'] = FALSE;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
You should be able to connect now at http://127.0.0.1/phpmyadmin
If you do not want to open the console each time you need to connect to your remote server, just create a batch file (by saving the 2 command lines in a .bat file).
You can set in the config.inc.php file of your phpMyAdmin installation.
$cfg['Servers'][$i]['host'] = '';
I would have added this as a comment, but my reputation is not yet high enough.
Under version 4.5.4.1deb2ubuntu2, and I am guessing any other versions 4.5.x or newer. There is no need to modify the config.inc.php file at all. Instead go one more directory down conf.d.
Create a new file with the '.php' extension and add the lines. This is a better modularized approach and isolates each remote database server access information.
In Ubuntu
Just you need to modify a single file in PHPMyAdmin folder i.e. “config.inc.php”.Just add below lines to your “config.inc.php”.
File location : /var/lib/phpmyadmin/config.inc.php OR
/etc/phpmyadmin/config.inc.php
Maybe you don't have the permission for editing that file, just give the permission using this command
sudo chmod 777 /var/lib/phpmyadmin/config.inc.php
OR (in different systems you may have to check with these two locations)
sudo chmod 777 /etc/phpmyadmin/config.inc.php
Then copy and paste the code in your config.inc.php file
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['verbose'] = 'Database Server 2';
$cfg['Servers'][$i]['host'] = '34.12.123.31';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
And make the appropriate changes with your server details
Locate the file libraries/config.default.php
then find $cfg['AllowArbitraryServer'] = false;
then set It to true
note:
on ubuntu the file in the path /usr/share/phpmyadmin/libraries/config.default.php
then you will find a new filed name SERVER in the main PHPMyAdmin page, you can add any IP or localhost for the local database.
Go to file \phpMyAdmin\config.inc.php at the very bottom, change the hosting details such as host, username, password etc.
Method 1 ( for multiserver )
First , lets make a backup of original config.
sudo cp /etc/phpmyadmin/config.inc.php ~/
Now in /usr/share/doc/phpmyadmin/examples/ you will see a file config.manyhosts.inc.php. Just copy in to /etc/phpmyadmin/
using command bellow:
sudo cp /usr/share/doc/phpmyadmin/examples/config.manyhosts.inc.php \
/etc/phpmyadmin/config.inc.php
Edit the config.inc.php
sudo nano /etc/phpmyadmin/config.inc.php
Search for :
$hosts = array (
"foo.example.com",
"bar.example.com",
"baz.example.com",
"quux.example.com",
);
And add your ip or hostname array save ( in nano CTRL+X press Y ) and exit . Done
Method 2 ( single server )
Edit the config.inc.php
sudo nano /etc/phpmyadmin/config.inc.php
Search for :
/* Server parameters */
if (empty($dbserver)) $dbserver = 'localhost';
$cfg['Servers'][$i]['host'] = $dbserver;
if (!empty($dbport) || $dbserver != 'localhost') {
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['port'] = $dbport;
}
And replace with:
$cfg['Servers'][$i]['host'] = '192.168.1.100';
$cfg['Servers'][$i]['port'] = '3306';
Remeber to replace 192.168.1.100 with your own mysql ip server.
Sorry for my bad English ( google translate have the blame :D )
In Windows with Wamp Server Installed you may find the configuration file
C:\wamp64\apps\phpmyadmin4.8.4\config.inc.php
Change the bolow line as appropriate
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = 3306;//$wampConf['mysqlPortUsed'];
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';
Delete complete entries of /etc/http/conf.d/phpMyAdmin.conf
And below entires in above file,
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
#ADD following line:
Require all granted
Require ip 127.0.0.1
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
#CHANGE following 2 lines:
Order Allow,Deny
Allow from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
Then,
run below command in MySQL prompt,
GRANT ALL ON *.* to root#localhost IDENTIFIED BY 'root#<password>'
GRANT ALL ON *.* to root#'%' IDENTIFIED BY 'root#<password>'
For reference: Allow IP to Access Secured PhpMyAdmin

phpMyAdmin 4.6.2 token mismatch

I'm getting the dreaded "token mismatch" error on my phpMyAdmin. My install lives in a vagrant/ansible box so it is a clean system.
If I have auth_type set to "cookie" I simply stay on the login page and if I set it to "http" I get the "token mismatch" error.
phpMyAdmin config.inc.php
$cfg['blowfish_secret'] = '123'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH!
$i = 0;
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http'; // or cookie
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
Nginx config:
server
{
listen 80 default;
server_name dev.company.local _;
root /var/www/sites/dev.company.local;
access_log /var/log/nginx/dev.company.local-access.log combined;
error_log /var/log/nginx/dev.company.local-error.log notice;
index index.html index.php;
include fastcgi_portal.conf;
location /phpmyadmin/(.*) {
alias /usr/share/phpMyAdmin;
}
}
I won't post my php.ini here as it such a huge file but few options are configured.
Things I've already checked:
session.gc_maxlifetime = 1440
session.save_path = /var/lib/php/session (set to 777, also tried /tmp)
mcrypt is enabled
clearing browser cookies etc
verified my mysql credentials
set the correct time + timezone of the VM
I found bug reports like https://sourceforge.net/p/phpmyadmin/bugs/3893/ but for me it does not seem to be fixed :)
Other info:
CentOS release 6.7 (Final)
nginx version: nginx/1.0.15
PHP 5.6.22 (fpm-fcgi) (built: May 26 2016 15:45:15)
I've tried the current phpMyAdmin version (4.6.2), the previous version (4.6.1) and the long-term version (4.4.15.6) all the same.
Any help would be great!
Assuming you are using Docker in Vagrant, then it's most likely caused by https://github.com/phpmyadmin/docker/issues/32.
It can be fixed by simply pulling newer version of the container :-).
I got exactly the same problem as you describe after security hardening of my Apache.
In my case it turned out to be the following that broke phpMyAdmin:
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
After commenting it out and restarting httpd everything worked again.
Supposedly the above header setting is to mitigate most of the common Cross Site Scripting attack using HttpOnly and Secure flag in a cookie but looks like PMA developers have not fully considered this scenario.

I changed MySQL port in XAMPP, now how do I listen to the new port?

I have installed the latest XAMPP with MySQL version 14.14 Distrib 5.6.21, the problem is in my computer, I already have a MySQL database installed by other program that I am using.
So I configure the XAMPP MySQL port to 3307 (default is 3306) inside the my.ini file. However, now my localhost/phpmyadmin seems to read the database installed by the other program, not the one in XAMPP, and also when I test using some PHP files, it shows that I am connected to the database even though XAMPP is turned off (XAMPP MySQL also disconnected).
How do I change the setting of my PHPMyAdmin and localhost to connect to the MySQL port 3307?
I don't understand how all these ports and the database work.
Goto xampp>phpMyAdmin Directory.
Find the config.inc.php file.
Now change this line:
$cfg['Servers'][$i]['host'] = '127.0.0.1';
To
$cfg['Servers'][$i]['host'] = '127.0.0.1:3307';
To configure phpMyAdmin to connect to a different port from the default, edit your config.inc.php file and add a line like:
$cfg['Servers'][$i]['port'] = '3307';
(of course substituting any port number as needed). You can also see the official documentation.
First open the following path:
C:\xampp\phpMyAdmin
Add the following string in config.inc.php file.
$cfg['Servers'][$i]['port'] = '3307';
The following worked for me, I just added my port code to:
$cfg['Servers'][$i]['host'] = '127.0.0.1:3308';
Add below line under phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['port'] = port number;
in my case the port number is 8111.

How can I disable the phpMyAdmin login page?

I use phpmyadmin, and when entering this adress:
www.mydomain.com/phpmyadmin
a login page appears.
Is there any way of disabling it, so it doesn't appear/exist?
Thanks
You can disable phpMyAdmin by disabling the module configuration.
sudo a2disconf phpmyadmin.conf
sudo /etc/init.d/apache2 restart
Enable it with
sudo a2enconf phpmyadmin.conf
sudo /etc/init.d/apache2 restart
In your config.inc.php file change:
$cfg['Servers'][$i]['auth_type'] = 'config';
and add
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password';
In centos, locate the file in directory /etc/httpd/conf.d/phpmyadmin.conf/ and uncomment these lines to only give access on the local system to phpmyadmin, and leave the users from outside with no access to phpmyadmin
<Directory "/usr/share/phpmyadmin">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
Hope this be helpfull
Yep, you can: set your password in the config file. BUT if you are using this on your domain then I'd strongly recommend you take it off your site altogether!
Use a client to access your database - like mysql workbench or mysql yog or any of the numerous ones out there.
If you MUST use phpmyadmin then why not install it on your local machine and add the details to the config there? It is much safer.
Preventing remote login doesn’t stop access to phpmyadmin if you have not stopped it in /etc/phpmyadmin/apache.conf
To turn the access to phpmyadmin OFF in ubuntu 14.04 with apache web server, edit /etc/phpmyadmin/apache.conf
Search for or if you set the Alias /phpmyadmin /usr/share/phpmyadmin in the same file.
Add or Edit following lines: Order Deny, Allow Deny from all
Restart apache2 with sudo service apache2 restart
To turn the access to phpmyadmin ON temporarily, first find out your ip address. Search Google, what is my ip address. Then edit vi /etc/phpmyadmin/apache.conf file. Add this line to the above mentioned Directory tag: Allow from
Restart the apache2 with sudo service apache2 restart
One thing you may want to do is just use a .htaccess file to redirect that URL somewhere to basically restrict the ability to get to that URL.
To do this, just create a .htaccess file at the root directory of your domain and put this in it:
Redirect 301 /phpmyadmin http://www.mydomain.com/
Then whenever you need to access phpmyadmin, you would just have to comment out that line temporarily while you do your work.
Just an idea. If someone must have PhpMyAdmin installed, it is also possible to "hide it" under another url.
In case of a Debian/Apache web server find the apache.conf in the phpmyadmin directory and change:
Alias /phpmyadmin /usr/share/phpmyadmin
to
Alias /yourspecialurl /usr/share/phpmyadmin
Don't forget to restart Apache with the new config...
To disable PhpMyAdmin page need to edit an configuration file as below
vi /opt/lampp/etc/extra/httpd-xampp.conf around 64th line edit:
Deny from all
TO
Deny from none
Order deny,allow
Deny from all /*none*/
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16
You can remove it completely with this command:
sudo apt-get purge phpmyadmin

Categories