Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Mysql broken after free trial end

My problem is simple: I have a website hosted on a GC compute engine VM. For the 3 months of trial, the website functioned normally, using a mysql database from within the VM. However, after 7 days after my billing account being upgraded to a billed, paid account, mysql is no more available. The error I'm getting is the following: ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (111).

Do you have any idea why this happened? Do you know how to solve it. The file /run/mysqld/mysqld.sock exists when ls command is run, but trying to view its contents with cat does not work.

Thank you in advance!

Solved Solved
1 5 333
1 ACCEPTED SOLUTION

Okay, did you've checked the logs? Typically  /var/log/mysql/error.log or /var/log/mysqld.log

Also, check the socket file existence. If doesn't exists,
simply perform following commands:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

 and restart service. 

Additionally you could check whether SQL is listening on 3306

sudo lsof -i -P -n | grep 3306

As a last step reinstall DB.

sudo apt-get remove --purge mysql-server mysql-client mysql-common

or

sudo yum remove mysql-server
sudo yum install mysql-server

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

View solution in original post

5 REPLIES 5

Hello @Serenus  ,Welcome on Google Cloud Community.

Are you using LAMP stack by any chance ? It looks like you have issue with sql DB configured at google cloud VM. If this is LAMP, I found this StackOverflow topic: https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-thr...

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

Hello! Thank you for your response!
Unfortunately, that is not the problem. I have indeed used a LAMP stack (aka installed apache2, mysql-server and php), but everithing worked just fine during the trial period. The website is a simple wordpress website.  It is served using the apache2 server and a mysql database using mysql-server. I haven't even installed phpmyadmin for it. The apache2 service is still working properly, but isn't able to connect to the database (as me personally am unable to connect to it through the terminal).

Okay, did you've checked the logs? Typically  /var/log/mysql/error.log or /var/log/mysqld.log

Also, check the socket file existence. If doesn't exists,
simply perform following commands:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

 and restart service. 

Additionally you could check whether SQL is listening on 3306

sudo lsof -i -P -n | grep 3306

As a last step reinstall DB.

sudo apt-get remove --purge mysql-server mysql-client mysql-common

or

sudo yum remove mysql-server
sudo yum install mysql-server

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

Thank you very much for your response, this solved my problem.

The socket file existed. Running chown and restarting the service did the job.

As a side note, do you have any idea if it was or why this was related to trial expiration? I can confirm that the problem appeared at midnight (GMT+3), since I was using resources provided by the server at that time.

Hmm, hard to say. What is coming to my mind is the situation where VM has been up, then trial has ended and VM got info that resources should be down. This could cause issue with socket. <- this is staggered theory tbh.

However, if you are saying that simple chown an restart fixed the problem, it's more probably that there were an update for Linux packages and OS itself changed owner of that socket. <- this fits better to the steps taken to mitigate the issue imho.