I am having a big problem trying to connect to mysql. When I run:
/usr/local/mysql/bin/mysql start
I have the following error :
<
If you are using AWS (Amazon Web Services) Micro version, then it is a memory issue. When I ran
mysql
from the terminal it would say
ERROR 2002 (HY000): Can't connect to local MySQL server through socket /var/run/mysqld/mysqld.sock' (111)
So I tried the following and it would just fail.
service mysqld restart
After much searching, I found out that you have to create a swap file for MySQL to have enough memory. Instructions are listed: http://www.prowebdev.us/2012/05/amazon-ec2-linux-micro-swap-space.html.
Then, I was able to restart mysqld.
I got this error when I set cron job for my file. I changed the permissions of file to 777 but it still not worked for me. Finally I got the solution. May be it will be helpful for others.
Try with this command:
mysql -h 127.0.0.1 -P 3306 -u root -p
Remember that -h means host, -P means port and -p means password.
sudo service mysql start
This should serve you just fine. There could be a possibility that you changed some commands that affected the mysql configurations.
Make sure you are running mysqld : /etc/init.d/mysql start
A quick workaround that worked for me: try using the local ip address (127.0.0.1) instead of 'localhost' in mysql_connect(). This "forces" php to connect through TCP/IP instead of a unix socket.
you can always start mysql server by specifying the location of the mysql.sock file using the --socket
option like
mysql --socket=/var/mysql/mysql.sock
This will work even if the location of socket file in specified in a different location in the my.cnf file.