9
votes

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!

7

7 Answers

11
votes

you could try starting your mysql first

> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
> 
> service mysql start or service mysql start
16
votes

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

12
votes

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>
2
votes

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

1
votes

You need to first start mysqld service on your machine. Use below command to start mysqld service

service mysqld start
0
votes

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.

0
votes

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!