15

I've been trying to set mysql and phpMyAdmin for the last 12 hours, without any success. And yes, after hours and hours of Google-ing I know that is a common problem and I've read similar queries on stackoverflow but still can't come with the solution.....

I've tried everything - from changing the

$cfg['Servers'][$i]['port']

in the config.inc.php file to 3306, 127.0.0.1....

typing the socket path in the config.inc.php file - both tmp/mysql.php and the /var/mysql/mysql.sock.

I've tried changing the socket path in the my.cnf file and the php.ini....but I keep getting the same error:

#2002 - No such file or directory
The server is not responding (or the local server's socket is not correctly configured).

I'm using MySQL (5.1.65), PhpMyAdmin (3.5.2.2) and PHP (5.3.8).

Bart Platak
  • 4,387
  • 5
  • 27
  • 47
Stella Antonova
  • 151
  • 1
  • 1
  • 3
  • post your `config.inc.php` code.. – 000 Oct 28 '12 at 04:12
  • 1
    Double check whether mysql is started or not. – tk_ Nov 27 '14 at 09:44
  • Possibly related to http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi – Roberto14 Oct 23 '16 at 19:36
  • Restart MySQL. OSx : `sudo /usr/local/mysql/support-files/mysql.server restart` , Linux: `sudo service mysql start` (Old v: `sudo /etc/init.d/mysql start`) – Sadee Jul 26 '17 at 16:19

9 Answers9

16

I have recently encountered this problem on Mac OS Sierra too. Apache server is working but mysql is not. After searching for a solution, reading lots of posts I found this solution. And it worked!

The solution is to navigate to the mysql folder, in my case its,

/Applications/MAMP/db/mysql56/

and remove all the files except folders. Then restart MAMP again.

natterstefan
  • 433
  • 4
  • 8
  • 21
  • 1
    This worked for me when `killall -9 mysqld` didn't. I recall it happening after a system crash where nothing terminated cleanly. – plong0 Jul 27 '18 at 05:58
  • I actually only had to `rm ib_logfile*` (in mysql directory; I also moved to a backup sub-folder instead of hard rm). I found databases were somehow corrupt if I had deleted `ibdata1` - mysqld started up and in phpMyAdmin I could see all tables listed in left panel, but not in main panel and could not access any tables either. Things returned to normal when `ibdata1` was restored and mysqld restarted once again. – plong0 Jul 27 '18 at 06:06
13
  1. Quit MAMP
  2. Open the terminal
  3. Type: killall -9 mysqld Restart MAMP
andrewoodleyjr
  • 2,971
  • 2
  • 21
  • 21
3

The problem I had with this was because PHP was trying to connect via a UNIX socket instead of TCP. This is similar to this error: Error when connecting to MySQL using PHP/PDO

First, make sure you have a my.cnf config for mysql then add your default socket location:

[mysqld_safe] socket = /tmp/mysql.sock

Next in your php.ini, let PHP know where it is:

mysql.default_socket = /tmp/mysql.sock
Community
  • 1
  • 1
Steve Tauber
  • 9,551
  • 5
  • 42
  • 46
3

Since you did not mention MAMP, I am assuming you are not using it so this is for a manual install but it will likely also work for MAMP.

In my experience, this is caused by the socket variable of your mysql. By default, MySQL uses /tmp/mysql.sock.

You can get the MySQL socket variable by logging into your MySQL and doing

show variables like '%socket%'

that will show you the location of the socket file.

Now, create a php phpinfo() file and look for mysql.default_socket under the mysql or mysqli section. Mine was /var/mysql/mysql.sock. This shows that PHP is looking for the file in a different location than mysql is using.

Assuming you have same values, open new terminal and enter

cd /var
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock

this will create a link to the mysql socket file inside the location PHP is checking from.

PHPMyAdmin should work now.

swedge218
  • 3,593
  • 1
  • 14
  • 13
2

Check the config file:

/* $cfg['Servers'][$i]['host'] = 'localhost'; */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['compress'] = false;

Restart MySQL: OSx : sudo /usr/local/mysql/support-files/mysql.server restart

Linux: sudo service mysql start (Old linux: sudo /etc/init.d/mysql start)

Sadee
  • 3,010
  • 35
  • 36
0

Had this problem on Windows 7 Ultimate, AppServ. Just reload SQL and Apache (but you need to reload both of them, reloading only Apache didn't worked).

PHPMyAdmin 4.6.6
Server: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
Server version: 5.7.17-log - MySQL Community Server (GPL)
PHP: 5.6.30
0

If you are using homebrew restart mariadb. I also had the same issue and after stopping and starting mariadb it started working again.

brew services restart mariadb

Lasithds
  • 2,161
  • 25
  • 39
0

Am using MAMP on a macbook pro running High Sierra, and in my case, I tried all the above but it still did not work for me so I did the following :

  1. Looking for where you installed your MAMP and more specifically, look for the "config.inc.php" file located in "/Applications/MAMP/bin/phpMyAdmin".

enter image description here

  1. Backup (ie. on a mac, right click and duplicate) the "config.inc.php" file before we touch it. You can call or rename it "config_old.inc.php"

  2. Open the file in your favorite IDE or text editor.

enter image description here

  1. Look for the following lines ;

i) $cfg['Servers'][$i]['host']

ii) $cfg['Servers'][$i]['port']

iii) $cfg['Servers'][$i]['socket']

Change from :

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

to :

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

Change from :

$cfg['Servers'][$i]['port'] = '3306';

/this might be your default. Just check to see from your MAMP installation preference , press CMD + , and confirm that port number you have specified. In my case I had changed it to 8889./

enter image description here

to :

$cfg['Servers'][$i]['port'] = '8889';

Again depending on where you installed your MAMP or to be more specific your mysql.

Change from :

$cfg['Servers'][$i]['socket'] = 'some_folder_path or EMPTY';

to :

$cfg['Servers'][$i]['socket'] = '/Applications/MAMP/Library/bin/mysql/mysql.sock';

After this modification, save and refresh in your web browser.

Worked for me. Hope this helps. Cheers.

AppEmmanuel
  • 144
  • 1
  • 6
-2

check that mysql-server already installed if not sudo apt-get install mysql-server

Nimeshka Srimal
  • 8,012
  • 5
  • 42
  • 57
  • 1
    `-1` because `apt-get` routine is for debian systems; this question was assigned a `macos` tag. It is also clearly stated in the question the version of MySQL being used. –  Aug 02 '18 at 02:58