Cannot log in to the MySQL server
Recently, the website often prompted “error in establishing database connection”. The first reaction was that MySQL database had a problem. If so, because phpmyadmin could not login in the background, the following error was suggested:
Connection for controluser as defined in your configuration failed.
We can do like below to fix it:
$ sudo /etc/init.d/mysql start * Starting MySQL database server mysqld [ OK ] * Checking for tables which need an upgrade, are corrupt or were not closed cleanly.
The table is marked as crashed and should be repaired
Checking MySQL error log file. Eg: vim /etc/mysql/my.cnf
log_error = /var/log/mysql/error.log
Open error log and checking the last 2 lines:
14:33:44 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_redirection_404' is marked as crashed and should be repaired 14:33:44 [Warning] Checking table: './wordpress/wp_redirection_404'
So it is table wp_redirection_404 issue. Then we login in phpmyadmin console and do repair table operation:
InnoDB: cannot allocate memory for the buffer pool
See below log content:
15:01:46 InnoDB: Using Linux native AIO 15:01:47 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12 15:01:47 InnoDB: Completed initialization of buffer pool 15:01:47 InnoDB: Fatal error: cannot allocate memory for the buffer pool 15:01:47 [ERROR] Plugin 'InnoDB' init function returned error. 15:01:47 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 15:01:47 [ERROR] Unknown/unsupported storage engine: InnoDB 15:01:47 [ERROR] Aborting
15:01:47 [Note] /usr/sbin/mysqld: Shutdown complete
Now we use swap space to fix it.
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 15.0239 s, 71.5 MB/s $ sudo mkswap /swapfile Setting up swapspace version 1, size = 1048572 KiB no label, UUID=c6e62d14-65e9-422d-ab18-14833437cf17
ubuntu@ip-172-31-24-13:~$ sudo swapon /swapfile #Add below line to the end of /etc/fstab /swapfile swap swap defaults 0 0