41

I have installed MySQL server enterprise 5.1 on my local machine and now I want to install phpMyAdmin, but it does not work.

I have unrared phpMyAdmin to my server root directory and browsed to "localhost/phpMyAdmin/setup/index.php", started a new server and the only setting I changed was filling in my MySQL password in the field "Password for config auth"

So now when I am trying to log in I get an error message saying "#2002 cannot log in to the mysql server phpmyadmin"

Does anyone know what's wrong? I've been having this problem since yesterday.

narancha
  • 411
  • 1
  • 4
  • 3
  • 1
    Are you using cookie authentication? This is where you do not have db credentials in the config file (except a host, I should think) and you supply username + password in the web application. I believe alternatively you can supply the credentials in the config file, and it skips the login process (obviously only suitable for non-internet servers). Can you log in from the mysql console (/path/to/mysql.exe -u username -h localhost -p) using the credentials you are using to log into phpMyAdmin? – halfer Aug 03 '12 at 13:55
  • Nothing will work,the same error occurred to me as well i tried many things but had no luck. I suggest you save your mysql data folder to some safe place and reinstall phpmyadmin. It will work fine and don't try to enter password next time – Akash Shah Mar 11 '13 at 17:21
  • 1
    @Reddox answer solved my problem. maybe this should marked as solved. – apis17 Jul 26 '13 at 00:20
  • Instead of directly editing the config file, try `sudo dpkg-reconfigure phpmyadmin` where you can select the new authentication method. Use host ip/name instead of localhost(which uses Unix socket which might have been disabled). – Bhargav Nanekalva Feb 17 '14 at 10:00

27 Answers27

118

If you're getting the #2002 Cannot log in to the MySQL server error while logging in to phpmyadmin, try editing phpmyadmin/config.inc.php and change:

$cfg['Servers'][$i]['host'] = 'localhost';

to:

$cfg['Servers'][$i]['host'] = '127.0.0.1';

Solution from Ryan's blog

Edit (20-Mar-2015):

Note that if you're on a fresh install, config.inc.php may not exist. You need to rename / copy config.sample.inc.php and then change the relevant line

kouton
  • 1,941
  • 2
  • 19
  • 34
  • 1
    recently changed server to listen (bind) to ::1 on windows 8. changing to localhost in config is works. – apis17 Jul 26 '13 at 00:19
  • 1
    Note that if you're on a fresh install, config.inc.php may not exist. You need to rename / copy config.sample.inc.php and then change the relevant line. – octern Mar 19 '15 at 15:43
  • 1
    In fact you're bypassing the real problem: MySQL socket configuration. MySQL uses socket for host=localhost but TCP for host=127.0.0.1 Check https://stackoverflow.com/a/13771199/1538221 and be sure that apache user has enough rights to acess mysql socket. – slamora Apr 30 '15 at 16:03
  • And for me the path to this file was `/etc/phpmyadmin/config.inc.php` – Imran Zahoor Aug 26 '15 at 15:12
  • In my case the opposite worked: changing 127.0.0.1 into localhost. – user2587656 Jan 12 '23 at 19:28
26

This is old but as it is the first result in Google,

Please note that this also happens when your MySql service is down,

I fixed this by simply restarting MySQL Server using:

/etc/init.d/mysql restart

in SSH (Command is for a CentOS/CPanel server)

Vladimir
  • 1,602
  • 2
  • 18
  • 40
9

Background: I am using Linux Mint 13. In my case, this error happened when I restarted the computer and my DHCP assigned a new local IP address (from 192.168.0.2 to 192.168.0.4) to my desktop.

sudo gedit /etc/mysql/my.cnf

Update

bind-address = 192.168.0.2

to

bind-address = localhost

This fixed the problem. Enjoy.

Zenexer
  • 18,788
  • 9
  • 71
  • 77
Knight
  • 93
  • 1
  • 4
  • 1
    Changing my `bind-address` from the default `127.0.0.1` to `localhost` fixed my issue I was having on my Ubuntu server. – Jared Dunham Nov 19 '14 at 19:43
  • thanks, it works. In my case I move my server to another IP with previous backup, so bind-address still using old IP. – fxbayuanggara Mar 20 '17 at 13:51
4

This can also be caused if you forget (as I did) to move config.inc.php into its proper place after completing the setup script.

After making the config folder and doing chmod o+rw config and going to localhost/phpmyadmin/setup and following those steps, you need to go back to the command line and finish things off:

mv config/config.inc.php .         # move file to current directory
chmod o-rw config.inc.php          # remove world read and write permissions
rm -rf config                      # remove not needed directory

See full instructions at https://phpmyadmin.readthedocs.org/en/latest/setup.html

Geoffrey Booth
  • 7,168
  • 5
  • 35
  • 42
  • This worked but it is still a little baffling. The setup tells you to move the config.inc.php file into the config/ directory. Even in the new phpMyAdmin, so it would seem as if this is where the file belongs but I suppose not. – superuserdo Jun 09 '15 at 14:18
4

After trying all of the above suggestions here is what fixed my #2002 error.

Add the following line to your config.inc.php file and change the number to your MySQL port:

$cfg['Servers'][$i]['port'] = '3307'; // MySQL port

I had multiple mysql instances installed, and in this case, I had updated my.ini to run MySQL on port 3307, but had not updated phpMyAdmin to reflect the new port. In my case, the line for the port did not exist in the config.inc.php file, so I was not aware that it needed updating.

jookyone
  • 141
  • 7
3

I've been through basically all of stackoverflow for this error and nothing resolved my issue. I was able to log into mysql directly from the linux command line fine, but with the same user and password couldn't log into phpmyadmin.

So I beat my head against the wall for half the day until I realized it wasn't even reading the config.inc.php under /etc/phpmyadmin (the only place it was located btw based on "find / -iname config.inc.php". So I changed the host in /usr/share/phpMyAdmin/libraries/config.default.php and it finally worked.

I know there's probably another issue with why it isn't reading the config from the /etc/phpmyadmin folder but I can't be bothered with that for now :P

tldr; if your settings don't seem to be applying at all try making the changes within /usr/share/phpMyAdmin/libraries/config.default.php

mbommel
  • 31
  • 3
  • Wow... Thanks for this... I was trying connect phpmyadmin to another LAN host and came across this issue.. This is the only solution that worked for me. – M_R_K Jul 03 '16 at 09:28
3

Did you set up the MySQL on your machine? It sounds like you're using Windows; MySQL runs as a "Service" on your machine (right-click My Computer -> Manage -> Services).

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
  • yes thats correct. I am using windows, MySQL is running as a service called MySQL and it is running. I also use IIS as a server not apache – narancha Sep 12 '10 at 11:10
2

I have also experienced the same thing, hopefully a this helps.

cd /etc/init.d
./mysql start

please login to access mysql and phpmyadmin

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
Eka Wijaya
  • 21
  • 1
2

It happened with me when I changed the instance type of my AWS server.

#2002 Cannot log in to the MySQL server can also occur when the mysqld service is not started.

So first of all you need to execute :

$ sudo service mysqld restart

This will give you :

$ sudo service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

After that the error will not come.

P.S. On EC2 instances, one should also change the host from localhost to 127.0.0.1 as mentioned in the top answer.

driftking9987
  • 1,673
  • 1
  • 32
  • 63
1
  • Right-click My Computer -> Manage -> Services
  • Choose "Services" under the "Services and Application" from right pane
  • Then search for the "Zend Development" Service.
  • When you find it, double click to start that service.

Now, you should be able log in to phpMyAdmin.

pjmorse
  • 9,204
  • 9
  • 54
  • 124
1

I had same issue after the server has been attacked using a DDoS (actually a penetration testing tool).

I've headed to /etc/var/mysql/error.log first to see the InnoDB had a file lock.

The issue was immediately fixed by restarting the server, however that's not future-proof.

igraczech
  • 2,408
  • 3
  • 25
  • 30
1

In my system, config.inc.php didn't exist, but config.sample.inc.php existed. Try copying the sample script to config.inc.php

Vikram
  • 23
  • 5
1

Had this problem a number of times on our setup, so I've made a check list.

This assumes you want phpMyAdmin connecting locally to MySQL using a UNIX socket rather than TCP/IP.

UNIX sockets should be slightly faster as they have less overhead and can be more secure as they can only be accessed locally.

Service

  • Is the mysqld service running? service mysqld status
  • .. If not service mysqld start
  • Has config has changed since service started? service mysqld restart

MySQL Config (my.cnf)

  • Check that there isn't a non-socket client protocol set, e.g. protocol=tcp
  • Check that the socket location is accessible and has the right permissions

PHP Config (php.ini)

If you can connect locally from the command line, but not from phpMyAdmin, and the socket file is not in the default location:

  • Set the mysqli default sockets to the new location: mysqli.default_socket = *location*
  • ... I also set the pdo_myql.default_socket and mysql.default_socket just to be sure
  • Restart your web service (httpd in my case) service httpd restart

phpMyAdmin Config (config.inc.php)

  • Check that the host is set to localhost: $cfg['Servers'][$i]['host'] = 'localhost';
  • The socket location can also be set here: $cfg['Servers'][$i]['socket'] = '*location*';

N.B.

As pointed out by @chk; Setting the $cfg['Servers'][$i]['host'] from localhost to 127.0.0.1 just causes the connection to use TCP/IP rather than using the socket and is more of a workaround than a solution.

The MySQL config setting bind-address= also only affects TCP/IP connections.

If you don't need remote connections, it is recommended to turn off TCP/IP listening with skip-networking.

Arth
  • 12,789
  • 5
  • 37
  • 69
1

For Ubuntu 14.04 and 16.04, you can apply following commands

First, check MySQL service is running or not using

sudo service mysql status

Now you can see you show a message like this: mysql stop/waiting.

Now apply command: sudo service mysql restart!

Now you can see you show a message like this: mysql start/running, process 8313.

Now go to the browser and logged in as root(username) and root(password) and you will be logged in successfully

0

In ubuntu OS in '/etc/php5/apache2/php.ini' file do configurations that this page said.

Raha
  • 29
  • 1
  • 1
  • 6
0

CAUTION: This method completely removes MySQL data!

I have same problem in Ubuntu 12.10 , mysql 5.5

I have tested lots of answer related to my issue but none of theme work

at last I had to reinstall remove my mysql server completely and then I install again Mysql server

but you should be aware that you should delete all directory which related to Mysql I use this link to remove mysql completely

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql
sudo rm -rf /var/run/mysqld

and then you install again LAMP by tasksel

Removing MySQL 5.5 Completely

https://serverfault.com/questions/254629/unable-to-install-mysql-server-in-ubuntu/296928#296928

Community
  • 1
  • 1
masoud2011
  • 896
  • 9
  • 10
0

For those who get this error when working with WAMP/XAMP on a windows machine.

This may help you.

Your solution is to

  • net stop mysql
  • Erase binary logs (and the binary log index file)
  • IF you do not know where they are, locate my.ini on your PC
  • Open my.ini in Notepad look for the option log-bin or log_bin
  • Look for the option datadir
  • If log-bin only has a filename, look inside the folder specified by datadir
  • If log-bin includes a path and a filename, look inside the folder specified by log-bin
  • Open the desired folder in Windows Explorer
  • Remove the binary logs There should be a file whose file extension is .index. Delete this as well net start mysql

Please DO NOT ERASE ib_logfile0 or ib_logfile1 when you have binary log issues.

Answer is on dba.stackexchange

Community
  • 1
  • 1
heyomi
  • 385
  • 5
  • 18
0

After Many attempts in getting this fixed, it was found out that the issue was with Mysql users not being allowed to login

netstat -na | grep -i 3306

If it is listening on all interfaces, then you can assign any of your interfaces to this

$cfg['Servers'][$i]['host'] = 'ANY INTERFACE';

Try to Login using the above IP using the comand line

mysql -u bla -p -h <Above_IP_address>

If this works then your phpmyadmin will also work, If not fix the mysql.user table so that the above command works and allows you to login to mysql.

niroshan.l
  • 11
  • 1
0

Right-click My Computer -> Manage -> Services Choose "Services" under the "Services and Application" from right pane Then search for the "mysql" Service. When you find it, double click to start that service.

Now you should be able to run and login to PhpMyAdmin

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
0

Check whether you server is running or not.

Rajilesh Panoli
  • 770
  • 10
  • 17
0

Just in case anyone has anymore troubles, this is a pretty sure fix.

check your etc/hosts file make sure you have a root user for every host.

i.e.

127.0.0.1   home.dev

localhost   home.dev

Therefore I will have 2 or more users as root for mysql:

root@localhost
root@home.dev

this is how I fixed my problem.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
Victor Bojica
  • 333
  • 1
  • 4
  • 14
0

I had an issue with the path of the MySQL service in the Windows 7 registry which was not changed with the new installed XAMPP or newer easyPHP version.

So if anybody has the same problem (#2002 error, phpMyAdmin cannot be started) you can search into the win regedit for 'my.ini' and exchange the path to the new package.

For example I exchanged on a few places the older path:

C:\EASYPH~1.1VC\binaries\mysql\bin\eds-mysqld.exe --defaults-file=C:\EASYPH~1.1VC\binaries\mysql\my.ini MySQL

with the newer one:

c:\xampp\mysql\bin\mysqld.exe --defaults-file=c:\xampp\mysql\bin\my.ini mysql

It is strange that nobody described this issue before on the web!

Francisco
  • 10,918
  • 6
  • 34
  • 45
0

It is because your system has two installations of "mysql" packages. One installation was made through xampp/lampp and another installation was made through mysql-debain package. To solve the problem, just go to "synaptic manager" and remove mysql, and then you will be able to access mysql from xampp server.

Note : removing mysql from synaptic manager doesn't affect mysql which was installed through xampp/lampp server. So don't worry!

0

For me the problem was solved by deleting a .pid file named after my computer:

sudo rm /var/mysql/computername.pid
0

This the following line in your php.ini file

mysql.default_socket = "MySQL"

to

mysql.default_socket = /var/run/mysqld/mysqld.sock
Ikelie Cyril
  • 130
  • 7
0

This problem occurs when you already had MySQL installed on your machine or in case you have changed the post number of the MySql service which is 3306(Default). In order to solve this, you have to tell the phpMyAdmin to look for another port instead of 3306. To do so go to C:\xampp\phpMyAdmin(default location) and open Config.inc and add this line $cfg['Servers'][$i]['port'] = '3307'; after $cfg['Servers'][$i]['AllowNoPassword'] = true; Restart the services and now it should work.

Francisco
  • 10,918
  • 6
  • 34
  • 45
0

my problem is solved by this step

  1. apt-get install mysql-server phpmy admin
  2. /etc/init.d/mysql restart
  3. done.