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\
check that mysql-server
already installed if not
sudo apt-get install mysql-server
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.
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 :
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"
Open the file in your favorite IDE or text editor.
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./
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.
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
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
)