Unable to log in to MySql through SSH. Getting Can't connect to local MySQL server through socket

Keywords: LAMP/MAMP/WAMP - AWS - Technical issue - Other
Description:
Getting This Error:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/opt/bitnami/mysql/tmp/mysql.sock’ (111)

WHEN I RUN STATUS COMMAND. I CAN SEE MYSQL IS NOT RUNNING.
sudo /opt/bitnami/ctlscript.sh status
apache already running
mysql not running
php-fpm already running

WHEN I START MYSQL AGAIN(Its says MYSQL Started):
sudo /opt/bitnami/ctlscript.sh start mysql
Started mysql

NOW WHEN I CHECK STATUS AGAIN(Now All 3 services are running):
sudo /opt/bitnami/ctlscript.sh status
apache already running
mysql already running
php-fpm already running

BUT STILL I’M GETTING THE SAME ISSUE.

Screenshot of mysqld.log: https://prnt.sc/123n81g

Hello @sajid1,

We have a Support Tool that will gather relevant information for us to analyze your configuration and logs. Could you please execute it on the machine where the stack is running by following the steps described in the guide below?

Please note that you need to paste the code ID that is shown at the end.

Regards

This is the code: v3555182-bcd1-bc09-6390-71edcbb9d921.
Screenshot: https://prnt.sc/126my60

@davidg I want to give you more details.

  1. The main issue is MySQL suddenly stops and then Laravel is unable to connect with MySQL. MySQL stops because of CPU burst. But this happens randomly.

  2. Everything starts working fine when we restart the virtual machine(AWS Lightsail Instance)

  3. Now you will think, that we have a very small machine and the project is very big. Its not like this. Our project is mid-size written in Laravel & Reactjs. And we use MySQL as a RDBMS.

  4. Now we’re testing our project and our database is almost empty or has very minimum data.

  5. Lightsail Instance Specification:

    4 GB RAM, 2 vCPUs, 80 GB SSD
    LAMP (PHP 7)

Hello @sajid1,

I could not see anything relevant in your support output tool. Memory, storage and CPU values are correct:

-----------------------------------
Check CPU usage for current processes
-----------------------------------
Running: ps -e -o pcpu,nice,state,cputime,args --sort -pcpu | awk '{print $1,$2,$3,$4,$5}'
In: /opt/bitnami

Output:

%CPU NI S TIME COMMAND
15.8 0 S 00:00:16 /opt/bitnami/bnsupport-tool
0.7 0 S 00:00:03 /opt/bitnami/mysql/bin/mysqld
0.3 0 S 00:00:02 /sbin/init
0.2 0 S 00:00:01 php-fpm:
0.2 0 S 00:00:01 php-fpm:
0.1 - S 00:00:00 [migration/1]
0.1 0 S 00:00:00 php-fpm:
0.1 0 S 00:00:00 /opt/bitnami/php/bin/php
0.0 0 S 00:00:00 [kthreadd]
0.0 -20 I 00:00:00 [rcu_gp]
0.0 -20 I 00:00:00 [rcu_par_gp]
...


-----------------------------------
Display amount of free and used memory in the system
-----------------------------------
Running: free -m
In: /opt/bitnami

Output:

              total        used        free      shared  buff/cache   available
Mem:           3947         983        2539          25         423        2716
Swap:             0           0           0
-----------------------------------
Check free amount of disk space
-----------------------------------
Running: df -h
In: /opt/bitnami

Output:

Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M  5.4M  390M   2% /run
/dev/xvda1       79G  3.1G   73G   5% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/xvda15     124M  278K  124M   1% /boot/efi
tmpfs           395M     0  395M   0% /run/user/1000

In order to debug MySQL performance, you can try to run the mysqltuner tool to analyze your MySQL configuration.

https://docs.bitnami.com/aws/apps/wordpress/troubleshooting/install-mysqltuner/

I highly recommend you post the MySQL Tuner output in a MySQL forum. I think that users with a deeper knowledge of MySQL can better suggest you.

I hope it helps

The output is fine because I restarted the machine a while ago before creating and sending you logs. When MySQL stop responding and consume all memory then I’m unable to connect SSH most of the time and if by change SSH connects then I can’t run any command. Its say something like NO MEMORY etc.

For future reference I opened issue here with logs.
https://github.com/major/MySQLTuner-perl/issues/552

I found the issue with cronjobs. which I disabled and but still running. please look at the Syslog in the zip file.

A detailed version of this issue is here. https://github.com/laravel/framework/discussions/37148

We also opened an issue for AWS technical team and this is the response we got from them. https://prnt.sc/12740rl

Logs.zip (123.4 KB)