I opened my application (in Rails) on Amazon EC2 and got an error - thus I checked the logs and there is following:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
10 hours ago was everything working yet. What's the problem? A lot of traffic?
The app is running on Micro Instance.
How to fix this issue and how to avoid it in the future?
Thank you very much
EDIT:
sudo find / -type s
---
/tmp/.sock
/dev/log
/var/lib/apt-xapian-index/update-socket
/run/mysqld/mysqld.sock
/run/acpid.socket
/run/dbus/system_bus_socket
/run/udev/control
find: `/proc/4739/task/4739/fd/5': No such file or directory
find: `/proc/4739/task/4739/fdinfo/5': No such file or directory
find: `/proc/4739/fd/5': No such file or directory
find: `/proc/4739/fdinfo/5': No such file or directory
In my case, the server had apparently restarted at some point, and mysql was not started when it did. I simply typed the command to start and it worked:
sudo service mysqld start
locate your locate my.cnf file see there for line as socket = ../../mysql.sock
you need to replace the path with your path as
socket = /run/mysqld/mysqld.sock
if the path matches let me know
Cross posting my response from here.
I had this same problem on an ec2 instance. These instructions worked perfectly for me:
Redhat Enterprise Linux - RHEL 5 / 6 MySQL installation
Type the following command as root user:
yum install mysql-server mysql
Redhat Enterprise Linux - RHEL 4/3 MySQL installation
Type the following command as root user:
up2date mysql-server mysql
Start MySQL Service
To start the mysql server type the following command:
chkconfig mysqld on
/etc/init.d/mysqld start
Setup the mysql root password
Type the following command to setup a password for root user:
mysqladmin -u root password NEWPASSWORD
Test the mysql connectivity
Type the following command to connect to MySQL server:
$ mysql -u root -p
In my case I used command below:
project_folder > mysql.server start
After system return SUCCESS message it worked OK.
mysql-server is not installed by default on the Amazon Linux AMI. Use these commands to install it:
$ sudo yum install mysql-server
$ sudo chkconfig mysqld on
$ sudo /etc/init.d/mysqld start
$ mysqladmin -u root password NEWPASSWORD
$ mysql -u root -p
To solve this error first find your socket file, run the following commands in terminal
mysqladmin variables | grep socket
For me, this gives:
| socket | /var/run/mysqld/mysqld.sock
Then, add a line to your Rails application: config/database.yml:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock
This will solve this problem.
Related
I'm trying to use a fresh installation of MySQL on Windows Subsystem for Linux (Ubuntu) and can't seem to ever connect to it. I always get the error:
WSL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I've tried:
Switching the configuration to use localhost instead of sockets (I instead get an error saying I can't connect through localhost)
Using --skip-grant-tables by editing /etc/mysql/mysql.conf.d/mysqld.cnf and restarting
The file /var/run/mysqld/mysqld.sock never shows up either, though I figure this is because WSL doesn't have perfect socket support to begin with but it should still work. I suspect the problem might be specific to WSL and maybe I should try updating to WSL2? I don't know what else the issue could be.
I have the same issue solved through the following steps.
Put these lines at the end of the file /etc/mysql/my.cnf:
[mysqld]
bind-address = 0.0.0.0
user=root
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
Then put these commands on terminal (NOTE: if dir is not there then create one):
chmod 777 -R /var/run/mysqld
chmod 777 -R /var/lib/mysql
chmod 777 -R /var/log/mysql
Then start MySQL using below command:
mysqld
Then open a new terminal and connect using the below command:
mysql -uroot -pYourPass
I had the same issue.
Follow these steps provided by Microsoft: Add or connect a database with WSL
Update your Ubuntu packages: sudo apt update
install MySQL with: sudo apt install mysql-server
Start a MySQL server: sudo /etc/init.d/mysql start
Start the security script prompts: sudo mysql_secure_installation
Open the MySQL prompt: sudo mysql
In ubuntu version of WSL2 use this.
sudo chmod g+rx /var/run/mysqld
sudo usermod -aG mysql $USER
Although M. Hamza Rajput's answer is working (checked), it might be the case that the problem happens simply because mysql is NOT running
Thus, start mysql service:
sudo service mysql start
and then you can call the secure installation
sudo mysql_secure_installation
ok here's the thing I tried installing MySQL-server and it did install perfectly no problem there.
later I had had to format my system and then when I tried to install it, it did install but it did not prompt for the root password. when I later tried to reset the root password here's the problem I get
user#user:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
user#user:~$ sudo mysqld --skip-grant-tables &
[3] 13831
user#user:~$ mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[3] Exit 1 sudo mysqld --skip-grant-tables
I tried resolving the 2002 error but I am unable to do so. any help will be appreciated.
from what I understand I should not get the 2002 error to proceed further
The error is probably due to error in installation. Try the following:
Ensure that my MySQL service is running by executing the following command in the terminal:
$ sudo service mysql start
Verify the state of the process:
$ ps -A|grep mysql
$ ps -A|grep mysqld
Then kill the process with the following command:
$ sudo pkill mysql
$ sudo pkill mysqld
Finally restart the service:
$ sudo service mysql restart
And run the following command:
$ mysql -u root -p
Step#1: Run this command:
sudo mysql_secure_installation
Step#2: press n
Step#3: input your password.
Step#4: press y for until it says All done!
or follow this video tutorial
Also to change the password use this command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
I have a Ubuntu 14.04. server with LAMP installed where an Owncloud is running. I tried to install paperwork which didn't work out but thats not the problem.
After restarting my server I tried to access my owncloud again but I am facing an internal server error. See following picture.
Owncloud error
I looked in the log /var/log/apache2/error.log and theres following phrase:
Lost connection to MySQL server during query' in ...
I tried to restart the mysql service but this error appears:
stop: Unknown instance:
start: Job failed to start
Then I tried to login to mysql with mysql -u root -p and follorwing error appears:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I've looked for the sockets on the machine with find / -type s and the socket was there: /run/mysqld/ .
I created a symbolic link and pasted it to /var/run/mysqld/mysqld.sock
Unfortnutely nothing worked. After restarting again I can't find the socket anymore the output of find / -type s is:
/dev/log
/run/php5-fpm.sock
/run/udev/control
find: `/proc/977/task/977/fd/5': No such file or directory
find: `/proc/977/task/977/fdinfo/5': No such file or directory
find: `/proc/977/fd/5': No such file or directory
find: `/proc/977/fdinfo/5': No such file or directory
Update
I've reinstalled the server so problem is over :D
If you install lampp server, run mysql first
sudo /opt/lampp/lampp startmysql
Then make "mysqld" directory in /var/run
cd /var/run
sudo mkdir mysqld
Link your mysql from lampp to /var/run/mysqld
sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock
run mysql -u root -p . hope may help you
If you install LAMPP server, run MySQL first
sudo /opt/lampp/lampp startmysql
Then make "mysqld" directory in /var/run
cd /var/run
sudo mkdir mysqld
Link your mysql from lampp to /var/run/mysqld
sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock
run MySQL
mysql -u root -p .
If MySQL fails with «mysql» not found, install:
sudo apt install mysql-client-core-5.7
sudo apt install mariadb-client-core-10.1
There is any issues with the mysql services. Please try to restart mysql services and check the mysql error logs for more information
I installed (on Ubuntu 13) MYSQL using
sudo apt-get install mysql
But after running
mysql -u root -p
and entering the password it gives the error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)
Please guide...
Problem:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Solution:
sudo service mysql start
I solved it by stopping the apache server first and restarting the mysql server
sudo service apache2 stop
sudo service mysql stop
sudo service mysql start
sudo service apache2 start
Hope this can help you
(Env: docker ubuntu16.04 container):
i run this code each time restart mysql server, it work for me:
sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
sudo service mysql start
Make sure that Mysql is installed, still able to reproduce the issue, Look for the file in sql/my.cnf file.
Verify that the Socket connection path in that file:
Location shown in the error is: /var/run/mysqld/mysqld.sock
Actually location in my.conf file : /home/user/mysql/tmp/mysqld.sock
home/sql/bin >> mysql -u root -p --socket=/home/user/mysql/tmp/mysqld.sock
In some version's you may find 'mysql.sock' instead 'mysqld.sock'
I know it's too late, but I had same problem today.
It solved by removing current mysql and reinstalling mariadb.
It worked for me.
sudo apt install mariadb-server
Create one micro instance swap space in Ubuntu
dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile
I have removed the preinstalled MySQL from CentOS 6 using the command-
yum remove mysql mysql-*
Now, I want to install "MySQl-server-5.5.28-1.linux2.6.i386.rpm" in my system.
But it could not start on my system. Please tell me how to start the MySQL with user account as well as in root also.
I have done this:-
[rex#dhcppc0 MySQL]$
[rex#dhcppc0 MySQL]$ su -
Password:
[root#dhcppc0 ~]# cd /home/rex/Documents/Software/MySQL
[root#dhcppc0 MySQL]# rpm -i MySQL-server-5.5.28-1.linux2.6.i386.rpm
package MySQL-server-5.5.28-1.linux2.6.i386 is already installed
[root#dhcppc0 MySQL]# mysql -u
-bash: mysql: command not found
[root#dhcppc0 MySQL]# mysql -u mysql
-bash: mysql: command not found
[root#dhcppc0 MySQL]# mysql.server start
-bash: mysql.server: command not found
MySQL-server-xxxx is package that contains only MySQL Server. Executable file for server is "mysqld" - "d" letter is for a daemon).
File that you trying to execute (mysql) is MySQL client. There is no client application in server package.
Please install MySQL-client-xxxx package, where xxxx is a version.
Execute the initscript below as a root user:
# /etc/init.d/mysql start
If you try to access the database from local client, you need to install MySQL-client-5.5.28-1.linux2.6.i686.rpm package.
Then you can control the MySQL database.
$ /usr/bin/mysql -u mysql