My website (Wordpress) sometime stoped working with below error message"
cannot connect to Datatabse
I checked the log file of MySQL and I found that crash-info as below:
----------
2021-01-21 0:44:59 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-01-21 0:44:59 0 [Note] InnoDB: Uses event mutexes
2021-01-21 0:44:59 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-01-21 0:44:59 0 [Note] InnoDB: Number of pools: 1
2021-01-21 0:45:00 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-01-21 0:45:00 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2021-01-21 0:45:00 0 [Note] InnoDB: Completed initialization of buffer pool
2021-01-21 0:45:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-01-21 0:45:00 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=215993122
2021-01-21 0:45:07 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-01-21 0:45:07 0 [Note] InnoDB: Uses event mutexes
2021-01-21 0:45:07 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-01-21 0:45:07 0 [Note] InnoDB: Number of pools: 1
2021-01-21 0:45:07 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-01-21 0:45:07 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2021-01-21 0:45:07 0 [Note] InnoDB: Completed initialization of buffer pool
2021-01-21 0:45:07 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-01-21 0:45:07 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=215993122
2021-01-21 0:50:02 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-01-21 0:50:02 0 [Note] InnoDB: Uses event mutexes
2021-01-21 0:50:02 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-01-21 0:50:02 0 [Note] InnoDB: Number of pools: 1
2021-01-21 0:50:02 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-01-21 0:50:02 0 [Note] InnoDB: Initializing buffer pool, total size = 16M, instances = 1, chunk size = 16M
2021-01-21 0:50:02 0 [Note] InnoDB: Completed initialization of buffer pool
2021-01-21 0:50:02 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-01-21 0:50:02 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=215993122
2021-01-21 0:50:02 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2021-01-21 0:50:02 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2021-01-21 0:50:02 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-01-21 0:50:02 0 [Note] InnoDB: Setting file '/opt/lampp/var/mysql/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-01-21 0:50:02 0 [Note] InnoDB: File '/opt/lampp/var/mysql/ibtmp1' size is now 12 MB.
2021-01-21 0:50:02 0 [Note] InnoDB: Waiting for purge to start
2021-01-21 0:50:02 0 [Note] InnoDB: 10.4.11 started; log sequence number 215993131; transaction id 221150
2021-01-21 0:50:02 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-01-21 0:50:02 0 [Note] InnoDB: Loading buffer pool(s) from /opt/lampp/var/mysql/ib_buffer_pool
2021-01-21 0:50:02 0 [Note] Server socket created on IP: '::'.
----------
I restarted MySQL and my website worked well. The version of my MySQL is: Distrib 10.4.11-MariaDB, for Linux (x86_64) Ubuntu verion 20.
This situation appeared few times for a month ago.
I did search the solution in some posts before, but still cannot fix this issue,
MySQL server crashes at least 2 times a week
Wordpress + PHP+ apache +mysql, mysql crash every 1/ month
Is anyone stuck in this case, and knows how to fix it?
Start MySQL on XAMPP Control panel.
Check the My SQL Error log “mysql_error.log” by clicking on the Logs button on XAMPP control panel.
Go to the “data” directory in the MySQL database. I installed XAMPP on D: drive on my computer & the MySQL “data” directory location of my computer was “/opt/lampp/var/mysql/”. You may have a different location.
Take Backup of MySQL “data” Folder
First of all, you should create a backup of the “data” folder using any compression software.
Give a name like “data_backup.zip” or any type of compression you wish. I used WinRAR compression software to compress & backup MySQL “data” folder.
Rename the “data” folder
Rename the “data” folder to “data-oldfiles”. This is very important to rename the data directory to any new directory name. Create a new “data” folder
Create a new folder and give the folder name as “data“
To solve the problem we need to create a new “data” directory in the mysql database. Copy content from “backup” folder
Go to the “backup” folder and copy all files.
Paste the files from backup folder to data folder
Now start the MySQL database from XAMPP.
Now, your MySQL database will start properly without showing any error.
Transfer all MySQL projects Database, Data file & Log files
If you have many database which was used for various projects, then you have to transfer all database from “data-oldfiles” folder to “data” folder.
Copy all databases from the data-old files and paste to the data folder.
Now you have to copy the data file “ibdata1” & all log files “ib_logfile0, ib_logfile1 ” from the data-old files folder to the data folder. If you have many id_logiles then copied all of them.
MySQL error This may be due to a blocked port, missing dependencies, improper privileges, a crash, or a shutdown by another method. Start MySQL from XAMPP
Now Start MySQL from XAMPP.
Go to phpMyAdmin to check all databases are available & working.
From Dom comment, and the instruction of expert @Kemmut from WordPress.
https://wordpress.org/support/topic/my-website-down-related-to-mysql-crashed-many-times-in-a-month/#post-13963272
I’ve checked all logs from my LAMPP since last month (PHP, MySQL and Apache).
I summarize the reason of MySQL crashed many times as below:
Your are right, in my case, the reason is OS Killed MySQL service because it took a lot of Memory (exceed my server capabilities: 1G RAM).
MySQL error log:
PHP error_log:
The reason make MySql took a lot of MEM is: A lot of the unexpected scanning requests came from unknown server (Since last month, my server got the biggest number was 27 request/sec from a single IP !!! ).
Apache access_log
To deal with this situation, there are some free Linux scripts, that based on iptables and ufw from this article that can be used to block that kind of junk request.
https://vivustandard.com/fix-mysql-stops-or-crashes-randomly/
16M is too small for
innodb_buffer_pool_size
; try 50M. 1GB VM is quite tiny.Also lower
max_connections
to 10.