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).
I have installed LAMP on my Ubuntu machine.
Where Apache2 and PHP5 have been installed properly as when I run apache2 -v and php5 -v I am getting their installed versions.
But I am not sure how do I check If My-SQL is properly installed or not.
Because when I run mysql -u root -p command, I am getting the below error.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Please help!
try to force redefining the root password:
sudo service mysql stop
sudo /usr/bin/mysqld_safe --skip-grant-tables &
mysql -h localhost
(now we are using mysql without carring to user privileges)
> USE mysql
> UPDATE mysql.user
SET authentication_string=PASSWORD('new_password')
WHERE user='root' AND host='localhost';
> quit
sudo mysqladmin shutdown
sudo service mysql start
that's all ...
now try to use mysql with the new password, like that:
mysql -uroot -p
Enter password: enter the new_password
it should work :)
For resolving this issue, you need to run following commands sequentially
sudo service mysql stop
sudo /etc/init.d/apparmor reload
sudo service mysql start
After that you can run the following command to go to mysql console
mysql -u root -p
mysql>
you could try starting your mysql first
> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
>
> service mysql start or service mysql start
Had the same issue and done so much of troubleshooting
finally i resolved the isssue by
Creating a error.log file
steps
create a log file under /etc/var/log/error.log
start mysql using the command
systemctl start mysql.service
After this mysql started sucessfully
You need to first start mysqld service on your machine. Use below command to start mysqld service
service mysqld start
Not sure if that would be helpful but I run into the same issue on my VPS. As it turned out I have run out of space by doing an hourly backup.
try this:
df -h
If you have 100% of disk usage then the server cannot write anything to the disk, no logs, no temp files, nothing.
I have removed some old backups. First find them (run inside backup folder)
find . -type f -name "backup-2016-01*"
This command will find any file whit name starting with backup-2016-01...
Then delete those files:
find . -type f -name "backup-2016-01*" -delete
Or move them to a different location. Then fun the df -h again to see if you have more space.
It helped me.
In my case, the cause of this error was my server ran out of memory. Check if that's the case by running
sudo journalctl -xe
# See if there's message below
Out of memory: Kill process 20967 (mysqld) score 155 o
If that's the case then it's time to Upgrade your server!
I installed mysql following instructions on this link on my fresh installation of OEL 5. However when I try to start the mysql service with service mysqld start I keep getting
chown: `mysql:mysql': invalid user
chown: `mysql:mysql': invalid user
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
When I try to check user's information with id mysql I get user does not exist and when I try to add user, it says user already exists!
If I try to start mysql or ecen check its version for instance, I get:
[root#localhost ~]# mysql -v
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Worst part is there is no mysql.sock file on my whole file system. I confirmed it by firing find / -name mysql.sock which returned empty result.
AM I missing some configuration step or something? I am absolutely clueless. Can someone please help me with this?
Please, which of the corresponding linux distribution are you using ? have you try to run it in sudo mode: sudo service mysqld start ? To see if mysql user have been created run cat /etc/passwd | grep 'mysql' or cat /etc/passwd; normally; it special user for specific purpose (here mysql administration).
First, I will write that why I want to do it.
When I run a Ruby on Rails' database rake comamnd, it showed:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I created that file:
touch /tmp/mysql.sock
and run the command again. I showed:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
I have search it by Google, most of them said that should check mysql's status.
I am using FreeBSD 9.1 now. From this article there is a good method to do that:
http://www.cyberciti.biz/faq/freebsd-start-stop-restart-mysql-server/
But unlucky, I can't find mysql-server in my /usr/local/etc/rc.d/ directory.
I want to know where my mysql is, so I run:
whereis mysql
It showed me this only:
mysql: /usr/local/bin/mysql
But when I try:
/usr/local/bin/mysql status
It showed:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
In other way, if I try to connect my mysql using this command:
mysql -utom -p1234 -h my_mysql_host_name
I can connect my local database.
I don't know the reason about /tmp/mysql.sock. It seems a bad issue.
Status:
# service mysql-server status
mysql is running as pid 45699.
# ps 45699
PID TT STAT TIME COMMAND
45699 ?? I 0:00.50 [mysqld]
Did you follow the MySQL installation instructions & ensure GNUMake was installed on the system prior to installing mysql? It sounds like your installation is only half there ... if at all.
You should have a startup script in /usr/local/etc/rc.d/mysql-server -- it's absence is a clue that the install isn't correct.
Lastly, you can't just "create" a socket in /tmp (.."touch /tmp...) and expect it to work. It's not there for a reason... Likely because your install isn't complete.
Once you have things installed right, you should be able to get the status by typing
https://dev.mysql.com/doc/refman/5.1/en/freebsd-installation.html
Type service mysql-server status
If you appears that mysql is not running.
Check file etc/rc.conf check your line mysql_enable="YES" If you have added manually.
After the service mysql-server start
If not working even now, do the following steps:
-Type service mysql-server stop
-go on var/db and delete mysql folder
-go on /tmp and delete mysql.sock
-type in console service mysql-server start
-Now check if mysql is running process.service mysql-server status
If it works now create an user :
mysql -u root
GRANT ALL PRIVILEGES ON *.* TO root#"%"
IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
BIG EDIT :
If you have not installed mysql:
Upgrade the ports: portsnap fetch extract
Move on mysq dir: cd /usr/ports/databases/mysql56-server
Make install: make install clean
Another EDIT :
If you want to decrease the time, you can use pkg. which takes about 5 minutes to install mysql with him.
With pkg : pkg install mysql56-server and it's done select Y to confirm install and wait . Now configure rc.conf and set mysql user , done
I am getting the following error when I try to connect to mysql:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Is there a solution for this error? What might be the reason behind it?
Are you connecting to "localhost" or "127.0.0.1" ? I noticed that when you connect to "localhost" the socket connector is used, but when you connect to "127.0.0.1" the TCP/IP connector is used. You could try using "127.0.0.1" if the socket connector is not enabled/working.
Ensure that your mysql service is running
service mysqld start
Then, try the one of the following following:
(if you have not set password for mysql)
mysql -u root
if you have set password already
mysql -u root -p
If your file my.cnf (usually in the etc folder) is correctly configured with
socket=/var/lib/mysql/mysql.sock
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 777 /var/lib/mysql/
that solved it for me
The MySQL server is not running, or that is not the location of its socket file (check my.cnf).
Most likely mysql.sock does not exist in /var/lib/mysql/.
If you find the same file in another location then symlink it:
For ex: I have it in /data/mysql_datadir/mysql.sock
Switch user to mysql and execute as mentioned below:
su mysql
ln -s /data/mysql_datadir/mysql.sock /var/lib/mysql/mysql.sock
That solved my problem
If you are on a recent RHEL, you may need to start mariadb (an open source mysql db) instead of the mysql db:
yum remove mysql
yum -y install mariadb-server mariadb
service mariadb start
You should then be able to access mysql in the usual fashion:
mysql -u root -p
Just edit /etc/my.cnf
Add following lines to my.cnf
[mysqld]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
Restart mysql and connect again
mysql -u user -p password database -h host;
In my case I have moved socket file to another location inside /etc/my.cnf
from /var/lib/mysql/mysql.sock to /tmp/mysql.sock
Even after restarting the mysqld service, I still see the error message when I try to connect.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
The problem is with the way that the client is configured. Running diagnostics will actually show the correct socket path. eg ps aux | grep mysqld
Works:
mysql -uroot -p -h127.0.0.1
mysql -uroot -p --socket=/tmp/mysql.sock
Does not Work:
mysql -uroot -p
mysql -uroot -p -hlocalhost
You can fix this problem by adding the same socket line under [client] section inside mysql config.
Check if your mysqld service is running or not, if not run, start the service.
If your problem isn't solved, look for /etc/my.cnf and modify as following, where you see a line starting with socket. Take a backup of that file before doing this update.
socket=/var/lib/mysql/mysql.sock
Change to
socket=/opt/lampp/var/mysql/mysql.sock -u root
MariaDB, a community developed fork of MySQL, has become the default implementation of MySQL in many distributions.
So first you should start,
$ sudo systemctl start mariadb
If this fails rather try,
$ sudo systemctl start mysqld
Then to start mysql,
$ mysql -u root -p
As of today, in Fedora the package is named mariadb
And in Ubuntu it is called mariadb-server.
So you may have to install it if its not already installed in your system.
Make sure you have enough space left in /var. If Mysql demon is not able to write additional info to the drive the mysql server won't start and it leads to the error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Consider using
expire_logs_days = 10
max_binlog_size = 100M
This will help you keep disk usage down.
Please check whether another mysql service is running.
Make sure you started the server:
mysql.server start
Then connect with root user:
mysql -uroot
Here's what worked for me:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
service mysqld restart
One way to reproduce this error: If you meant to connect to a foreign server but instead connect to the non existent local one:
eric#dev ~ $ mysql -u dev -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/var/lib/mysql/mysql.sock' (2)
eric#dev ~ $
So you have to specify the host like this:
eric#dev ~ $ mysql --host=yourdb.yourserver.com -u dev -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 235
Server version: 5.6.19 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| performance_schema |
+-------------------------+
3 rows in set (0.00 sec)
mysql> exit
Bye
eric#dev ~ $
If your mysql was previously working and has stopped suddenly just "reboot" the server.
Was facing this issue on my CentOS VPS.->
Was constantly getting
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'(2)
Tried all techniques, finally restarting the server fixed the issues ->
shutdown -r now
Hope this helps !!
try
echo 0 > /selinux/enforce
if you change files in /var/lib/mysql [ like copy or replace that ], you must set owner of files to mysql this is so important if mariadb.service restart has been faild
chown -R mysql:mysql /var/lib/mysql/*
chmod -R 700 /var/lib/mysql/*
First enter "service mysqld start" and login
It worked for me with the following changes
Whatever path for socket is mentioned in [mysqld] and same in [client] in my.cnf and restart mysql
[mysqld]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
Please ensure you have installed MySQL server correctly, I met this error many times and I think it's complicated to debug from the socket, I mean it might be easier to reinstall it.
If you are using CentOS 7, here is the correct way to install it:
First of all, add the mysql community source
yum install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Then you can install it by yum install mysql-community-server
Start it with systemctl: systemctl start mysqld
My problem was that I installed mysql successfully and it worked fine.
But one day, the same error occurred.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
And no mysql.sock file existed.
This sollution solved my problem and mysql was up and running again:
Log in as root:
sudo su -
Run:
systemctl stop mysqld.service
systemctl start mysqld.service
systemctl enable mysqld.service
Test as root:
mysql -u root -p
mysql should now be up and running.
I hope this can help someone else as well.
Note that while mysql reads the info of the location of the socketfile from the my.cnf file, the mysql_secure_installation program seems to not do that correctly at times.
So if you are like me and shuffle things around at installationtime you might get into the situation where you can connect to the database with mysql just fine, but the thing can not be secured (not using that script anyway).
To fix this the suggestion from sreddy works well: make a softlink from where the script would expect the socket to where it actually is. Example:
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
(I use /tmp/ as a default location for sockets)
This might be a stupid suggestion but make 100% sure your DB is still hosted at localhost. For example, if a Network Admin chose (or changed to) Amazon DB hosting, you will need that hostname instead!
In my case, I was importing a new database, and I wasnt able to connect again after that. Finally I realized that was a space problem.
So you can delete the last database and expand you hard drive or what I did, restored a snapshot of my virtual machine.
Just in case someone thinks that is useful
I came to this issue when i reinstall mariadb with yum, which rename my /etc/my.cnf.d/client.cnf to /etc/my.cnf.d/client.cnf.rpmsave but leave /etc/my.cnf unchanged.
For I has configed mysqld's socket in /etc/my.cnf, and mysql's socket in /etc/my.cnf.d/client.cnf with customized path.
So after the installation, mysql client cannot find the mysql's socket conf, so it try to use the default socket path to connect the msyqld, which will cause this issue.
Here are some steps to locate this isue.
check if mysqld is running with ps -aef | grep mysqld
$ps -aef | grep mysqld | grep -v grep
mysql 19946 1 0 09:54 ? 00:00:03 /usr/sbin/mysqld
if mysqld is running, show what socket it use with netstat -ln | grep mysql
$netstat -ln | grep mysql
unix 2 [ ACC ] STREAM LISTENING 560340807 /data/mysql/mysql.sock
check if the socket is mysql client trying to connect.
if not, edit /etc/my.conf.d/client.cnf or my.conf to make the socket same with it in mysqld
[client]
socket=/data/mysql/mysql.sock
You also can edit the mysqld's socket, but you need to restart or reload mysqld.
Just rain into the same problem -- and here's how I addressed it.
Assuming mysqld is running, then the problem might just be the mysql client not knowing where to look for the socket file.
The most straightforward way to address this consists in adding the following line to your user's profile .my.cnf file (on linux that's usually under /home/myusername):
socket=<path to the mysql socket file>
If you don't have a .my.cnf file there, then create one containing the following:
[mysql]
socket=<path to the mysql socket file>
In my case, since I moved the mysql default data folder (/var/lib/mysql) in a different location (/data/mysql), I added to .my.cnf the following:
[mysql]
socket=/data/mysql/mysql.sock
Hope this helps.
ran into this issue while trying to connect mysql in SSH client, found adding the socket path to the command helpful when switching between sockets is necessary.
> mysql -u user -p --socket=/path/to/mysql5143.sock
This is a problem if you are running out of disk space.
Solution is to free some space from the HDD.
Please read more to have the explanation :
If you are running MySQL at LINUX check the free space of HDD with the command disk free :
df
if you are getting something like that :
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 5162828 4902260 0 100% /
udev 156676 84 156592 1% /dev
/dev/sda3 3107124 70844 2878444 3% /home
Then this is the problem and now you have the solution!
Since mysql.sock wants to be created at the mysql folder which is almost always under the root folder could not achieve it because lack of space.
If you are periodicaly give the ls command under the mysql directory (at openSUSE 11.1 is at /var/lib/mysql) you will get something like :
hostname:/var/lib/mysql #
.protected IT files ibdata1 mysqld.log systemtemp
.tmp NEWS greekDB mysql mysqld.pid test
ARXEIO TEMP1 ib_logfile0 mysql.sock polis
DATING deisi ib_logfile1 mysql_upgrade_info restore
The mysql.sock file appearing and disappearing often (you must to try allot with the ls to hit a instance with the mysql.sock file on folder).
This caused by not enough disk space.
I hope that i will help some people!!!!
Thanks!
I had to disable explicit_defaults_for_timestamp from my.cnf.