phpMyAdmin: Cannot log into the MySQL server no er

2019-06-05 03:13发布

I recently copied my mysql db into a new data directory and changed a few settings.

I also accidentally deleted my user directory /home/user and had all the fun of the fair recreating that.

I can now connect to mysql on the command line but cannot connect via phpMyAdmin. I get the message:

Cannot log in to the MySQL server

I have seen this before, but not without the error code #1045 or #2002 prepended.

Would there be any logs or documentation anywhere about this message without an error code?

UPDATE

phpMyAdmin is installed on the same server and prompts the web user for a username/password in the browser login page, on submit with the correct details it returns to this login page with the error message displayed.

I have tried changing the /etc/phpMyAdmin/config.inc.php line to:

$cfg['Servers'][$i]['host'] = '127.0.0.1'; // previously 'localhost'

I have also tried FLUSH PRIVILEGE to no avail.

3条回答
一夜七次
2楼-- · 2019-06-05 03:53

According to me the following can be the issue and the ways to resolve it

Causes:

--> path to save php_session is not set or is uncorrectly set:

--> Either php do not have sufficient rights to write to session directory or the directory does not exists.

Solution:

  1. To define the php_session directory add the below line to php.ini file:

    session.save_path="/tmp/php_session/"

  2. And give the write rights to the http server.

    Mostly, the http server run as user daemon in group daemon. For this case, the following commands will do the work for you :

    chown -R :daemon /tmp/php_session

    chmod -R g+wr /tmp/php_session

  3. restart http server.

Try it out and let me know


UPDATE

I have found this:-

In some rare cases, if your MySQL process has existed for a long time without any updates to your password, it may be storing your password in a format phpMyAdmin can't authenticate against. This will cause you to be unable to log in via phpMyAdmin, even with the correct username and password. In these cases, it is usually sufficient to change your MySQL password by another means (e.g. the command line), even if you "change" the password to the same thing.

so try just resetting your password through command line as

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

查看更多
对你真心纯属浪费
3楼-- · 2019-06-05 04:00

Finally fixed it, after much confusion.

Turns out, my my.cnf file was binding the address to our server's internal network IP.

bind-address = 192.168.etc

Previously, before moving the database (and socket location), it was also connecting with 'localhost' correctly (which uses the socket) and allowing login from phpMyAdmin.

After moving the db, the socket connection didn't work, and changing the config.inc.php line to 127.0.0.1 from localhost causes mysql to connect with TCP instead of the socket. This now caused conflict with the bind-address:

$cfg['Servers'][$i]['host'] = '127.0.0.1'; // previously 'localhost'

Removing the bind-address restriction allowed me to login.


A better solution however, was of course to fix the socket connection.

After fussing over permissions for a while, and asking around, someone help me find a setting in mysqli.ini (the extension phpMyAdmin uses to connect to the db):

mysqli.default_socket = /new/location 

This fixed the localhost socket connection and I could reinstate my my.cnf bind-address and revert config.inc.php to use 'localhost' again.

查看更多
爷、活的狠高调
4楼-- · 2019-06-05 04:15

in my situation, I just switch the php version from:5.6.16 to 7.0 and then it got login to nothing.

just switch it back, maybe reboot server it will support work in PHP 7.0

查看更多
登录 后发表回答