Can't start phpMyAdmin. Keep getting the #2002 socket error - mysql

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).

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.

Quit MAMP
Open the terminal
Type: killall -9 mysqld Restart MAMP

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

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.

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)

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

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

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 :
Looking for where you installed your MAMP and more specifically, look for the "config.inc.php" file located in "/Applications/MAMP/bin/phpMyAdmin".
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.
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./
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.

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

Related

Manjaro Linux: I can't run Mariadb because missing socket

Well, I have Manjaro/Linux 17.0, and I've tried to install MariaDB but I always get the same error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")
I don't know what to do, I've search in thousands of forums, I can't start the mariadb's deamon with systemctl, I tried to do a touch at /run/mysqld/mysqld.sock but then it refused my connection when I tried to start mariadb, and I tried to uninstall/reinstall MariaDB, but it's the same thing :(
In all my directories I can't find mysql.sock or similar.
Help me please!
I had the same problem, the solution which worked for me is https://serverfault.com/a/813123 , I just cleaned:
sudo rm /var/lib/mysql/*
then initialised the database:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
It seems like there might be a difference between what the server is using as the socket and what the client thinks should be the socket.
You can check the process list (ps -ef | grep mysql) and see if the server is running with a different socket setting than you expect. (Look for --socket=.)
Edit your /etc/my.cnf, find or make a [client-server] section, and set socket to a file that makes sense. It should be in a directory that users have access to. The default setting is socket=/tmp/mysql.sock, so that should be a safe bet. Then remove any other socket setting elsewhere in /etc/my.cnf or files in the /etc/my.cnf.d/ directory. Then restart, and it should hopefully work.
Also check if you have a personal config file ~/.my.cnf, look for a socket setting in there, and if so remove it.
For reference, see the socket entry in the MariaDB KB. Also, have a look at the full list of locations where MariaDB config files could be stored here.

Can't connect to local MySQL server through socket (From time to time)

I have a LAMP stack setup. Occasionally, I get the following error message when I open some page from the browser:
Error creating the connection!: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I think the server was configured correctly. The problem happens about every two months. Every time when I reboot the Linux server, or restart mysql, the problem was gone. I want to fix this problem permanently. Can anyone give me some idea?
Much appreciated.
EDIT
The problem occurs again and I checked the mysqld.sock file, it was not there. Do you have any idea how to fix the problem? – Ryan Jul 23 at 16:24
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with
socket=/var/run/mysqld/mysqld.sock
modified
#bind-address = 127.0.0.1
to
bind-address = localhost
you can check if mysql is running with the following command:
mysqladmin -u root -p status
try changing your permission to mysql folder. If you are working locally, you can try:
sudo chmod -R 755 /var/run/mysqld/
And then restart the mysql.
Good luck.
Could it be the log file getting too large and rebooting flushes it. See this in docs on server maintenance and logfiles. Also see discussion at digital ocean. Appears to be confirmed by discussion at serverfault
You could try change the permission of your MySQL sock file like this:
chmod 777 '/var/run/mysqld/mysqld.sock'
It is a test to see if whatever user mysqld is using, it will acess your mysqld.sock file. So, reboot your MySQL and change the permission of mysqld.sock. And you need to check that if your sock folder can be accessed through any mysqld process.
If the mysqld.sock file doesn't exist, that is to say your config file is not correct.Check your mysql config file in /etc/mysql/my.conf, find the socket config just as Vanya Avchyan says.
I think the socket config is /var/run/mysqld/mysqld.sock, but in fact your mysql process runs in other place sock file.
I used to met that problem, the real socket file exists in /tmp/mysqld.sock.
So run
sudo find / -name 'mysqld.sock'
to find the real sock file and change my.conf to this real place, restart your mysql. May have work.

mysql server does not shutdown with the error : 'the server quit without updating pid file'

environment
OS X El Capitan 10.11 , Mysql 5.6.26
What I did
mysql port was 3307 when I installed it. ( I didn't install it using brew.)
I changed the port 3306 to 3306 by editing /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist after using mysql with 3307 port for 6 months well.
I revised <string>--port=3307</string> to 3306.
I tried to stop and It didn't work. So I used following:
sudo kill -9 [PID]
It's killed and didn't start. So I changed the port 3006 to 3007.
I tried to start mysql server with following command and got a error.
sudo /usr/local/mysql/support-files/mysql.server start
ERROR! The server quit without updating PID file (/var/lib/mysql/nhnui-MacBook-Pro.local.pid).
And I found some helpful advices in follwing link.
reference link :
After MySQL install via Brew, I get the error - The server quit without updating PID file
I tried to change ownership of files, checking my.cnf file, checking error log file and all didn't work for me.
Finally, I removed /usr/local/mysql/datamysqld.local.err , /usr/local/mysql/datamysqld.local.pid and rebooted mac.and I can start mysql server.
The Problem
Then, the problem is above tip is not perfect for me.
mysql server was running after restarting mac. I checked it with 'ps-ef | grep mysql'.
Stop and start was success and then it didn't stop it again cause of same error!
Screenshot of the error :
Of course, I did it again (I mean deleting .err , .pid file / rebooting mac / cheking mysql ps / stop - start (well) / stop (got error)) and checked that it has same error.
Here is the error log : /usr/local/mysql/data/mysqld.local.err
Now, mysql server can't stop.
What can I do to solve this?
P.S - If it will be better to reinstall mysql, I should do that.
Make a backup of your system.
Dump your data into text files.
Uninstall everything releated to mySql (a quick Google search will point you to several how-tos)
Reinstall mySql from the package in the .dmg available from mySql website.
You can choose the latest 5.6.x or 5.7.x
Set the mySql root password and you're done.
When things get messy and all you can do is guessing what's the fix it's faster to reinstall given that a package installer is provided for mySql (you don't have to compile it yourself or play with brew/macports).

#2002 Cannot log in to the MySQL server

I am working on a windows server 2012 and trying to get PHPMyAdmin working. I cant get it to connect to the MySQL by root user or a non root user. I have searched and searched all over google. everywhere I saw it said to set allowroot and change localhost to 127.0.0.1 in the config.inc.php file. At first I could not find this file but then I read you have to change config.default.php to it and put it in the root folder. I did that. and here is what I changed
$cfg['Servers'][$i]['host'] = "127.0.0.1"
//already had the next one set
$cfg['Servers'][$i]['AllowRoot'] = true
I still cant get it to login from any user on MySQL, and I keep getting the error
#2002 Cannot log in to the MySQL server.
config.inc.php: http://u16626886.onlinehome-server.com/config.inc.zip
Testing PHP and MySQL: http://u16626886.onlinehome-server.com:801/test.php
I figured out the problem just need to solve it now. If I put MySQL on the C: drive it works fine but if I put it on the D: drive, which is where I want it, PHP can not connect to it. Does anyone know why that is?
It may be Mysql service is not running, try to start Mysql service
Sometimes Mysql Service May Not Run..
Try the following
1. Remove/Unstall the service
a) Start Cmd As Administrator
b) Type Mysql --remove
2. Restart Pc
3. Install
a) Start Cmd As Administrator
b) Use Cd ../ To locate the path for Mysqld (For me it is in C:\xampp\mysql\bin)
c)Type mysqld --Install
4. Restart Pc
This is a 2002 MySQL Socket error, we can resolve this quickly by executing following command
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Note: Above path is based on MAC, so you can change the path according to your OS
This was solved my problem on mac.
-config.inc.php-
change
$cfg['Servers'][$i]['AllowNoPassword'] = false;
to
$cfg['Servers'][$i]['AllowNoPassword'] = true;
and then,
-go to terminal -
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
and then come back and reloaded page.
Run SKYPE then using the menus do this:
Tools -> Options -> Advanced -> Connection
Un-Check the checkbox next to 'Use port 80 and 443 as alternatives for incomming connections'
Now restart SKYPE for these changes to take effect.

MySQL - Mac - Error 2002 - Can't connect to local... through socket

I had MySQL running fine on my Mac till earlier today when I installed homebrew and also updated my Path.
When I try to run mysql from my ternimal window now, I get the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I can't connect MySQLAdmin either.
I can't even run Mysqld. The error I get when trying to run mysqld is that it can't create test file.
I also tried to telnet localhost 3306 and wasn't able to connect.
Any help would be appreciated as I am fairly new to Mac.
If it's homebrew installation try:
$ mysql.server start
Basically, all you have to do is:
Go to "System Preferences"
Then, if MySQL is installed you should see a "MySQL" icon in the "Other" section right at the bottom. Click on it.
Click on "Start MySQL Server"
You will now be able to start the MySQL command prompt without getting the "Can't connect..." error.
The mysql error (2002) is caused by the fact mysqld isn't running. The error you are seeing when starting mysqld is probably a permissions issue. Try starting mysqld as root or sudo'ing the command.
I'm user of osX 10.11.3 (El Capitan)
first of all, check your mysql version.
$ mysql --version
check the server is already running.
$ ps -ex | grep mysql
If you checked this following string, that means mysql server is already running.
=> mysqld_safe / --pid-file=#{path}
(The mysql pid file created when mysql server running to succeessfully. )
In that case, you have to stop mysql server.
$ mysql.server stop
and start your mysql server
$ mysql.server start
Starting MySQL
SUCCEESS!
and start(or restart) your mysql server
$ mysql.server start
$ mysql.server restart
If you failed to start mysql server, please leave me error message when you run mysql.server start
It may also be that the address to your sock-file is wrong in php.ini.
Open up the terminal, and run the following:
netstat -ln | grep mysql
This will show the correct path to your socket. Check it versus the address in php.ini. If it's wrong, then correct it.
Go to phpMyAdmin/config.inc.php edit the line
$cfg['Servers'][$i]['password'] = ''; to $cfg['Servers'][$i]['password'] = 'yourpassword';
And the last thing $cfg['Servers'][$i]['extension'] = 'mysql'; change this to $cfg['Servers'][$i]['extension'] = 'mysqli'; Now restart your server. and see .
This problem might occur due to setting of a password to root thus phpmyadmin is not able to connect to the mysql database.
I know this question is old but I fix this doing those followings commands
cd /usr/local/mysql
sudo ./bin/mysqld_safe
my_mac_password
Ctrl + Z
bg
Ctrl + D
quit the terminal
The problem is that I have to do this each time I reboot my mac.
Source: http://openclassrooms.com/courses/administrez-vos-bases-de-donnees-avec-mysql/installation-de-mysql