Mysql often crashes [duplicate] - mysql

This question already has answers here:
Amazon EC2, mysql aborting start because InnoDB: mmap (x bytes) failed; errno 12
(7 answers)
Closed 3 years ago.
My Mysql server often crashes, and I need to restart mysql using "service mysqld start" command.
I check the mysql error log file.
130807 22:59:47 mysqld_safe Number of processes running now: 0
130807 22:59:47 mysqld_safe mysqld restarted
130807 22:59:47 [Note] Plugin 'FEDERATED' is disabled.
130807 22:59:47 InnoDB: The InnoDB memory heap is disabled
130807 22:59:47 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130807 22:59:47 InnoDB: Compressed tables use zlib 1.2.5
130807 22:59:47 InnoDB: Using Linux native AIO
130807 22:59:47 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
130807 22:59:47 InnoDB: Completed initialization of buffer pool
130807 22:59:47 InnoDB: Fatal error: cannot allocate memory for the buffer pool
130807 22:59:47 [ERROR] Plugin 'InnoDB' init function returned error.
130807 22:59:47 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130807 22:59:47 [ERROR] Unknown/unsupported storage engine: InnoDB
130807 22:59:47 [ERROR] Aborting
130807 22:59:47 [Note] /usr/libexec/mysqld: Shutdown complete
130807 22:59:47 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
I have about 10,000 users and I have a database which have 10,000 tables. Those tables are used for recording the user status. And, when I create a new user table, I use the following code with PDO.
$statusTable = "status_".$uid;
$qstr = "CREATE TABLE IF NOT EXISTS `status`.`$statusTable` (
`prim_id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`message` VARCHAR( 600 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`created_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = INNODB";
$db->query($qstr);
Does this code cause mysql crash? I use EC2 instance with 615MB ram. Thanks!!

Aside from a very bad database design, your question/problem seems to have been posted and answered before.

EASY ANSWER: You do not need to create a new table for every user to track their status. You are using their $uid so, you can use a single table with a column uid to track their data. Then when you want to get their data, use $uid such as
SELECT * FROM user_data
WHERE uid=$uid
Also, you can set a cron scheduler to restart MySQL if it crashes.
* * * * * systemctl is-active --quiet mysqld || systemctl restart mysqld
DETAILED ANSWER:
This is an important question especially for people who are using a very small VPS, say 1GB of RAM or less. If MySQL is dropping out, it may be a problem with your server configuration (Apache | nginx) or MySQL configuration. DOS attacks may cause an increased spike in system resource usages (see image). The end result is that MySQL process gets shutdown by the Kernel. For a long-term solution should look at optimizing your Apache or MySQL configurations.
There are several other discussions Stack Overflow those topics as well as the MySQL manual and Percona Blog:
MySQL Manual - How MySQL Uses Memory:
https://dev.mysql.com/doc/refman/8.0/en/memory-use.html
Percona - Best Practices for Configuring Optimal MySQL Memory Usage:
https://www.percona.com/blog/2016/05/03/best-practices-for-configuring-optimal-mysql-memory-usage/
How to Optimize MySQL Performance Using MySQLTuner:
https://www.linode.com/docs/databases/mysql/how-to-optimize-mysql-performance-using-mysqltuner/
Apache Memory Usage Configuration:
https://serverfault.com/questions/254436/apache-memory-usage-optimization
Apache Manual on Performance Tuning:
https://httpd.apache.org/docs/2.4/misc/perf-tuning.html
Tuning Apache Server:
https://www.linode.com/docs/web-servers/apache-tips-and-tricks/tuning-your-apache-server/
However, with respect to your original question, yes, you can script a temporary solution that checks if MySQL service is loaded and active and will restart MySQL if it is not loaded and active.
You did not mention what operating system you are using. That would help to give you a specific command. I will give you an example for CentOS linux.
Look at the following output of the command systemctl status mysql. You can see at the top that the service is loaded and active.
[root#centos-mysql-demo ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-06-18 18:28:18 UTC; 924ms ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3350 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 3273 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 3353 (mysqld)
CGroup: /system.slice/mysqld.service
└─3353 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jun 18 18:28:11 centos-mysql-demo systemd[1]: Starting MySQL Server...
Jun 18 18:28:18 centos-mysql-demo systemd[1]: Started MySQL Server.
If the service is not loaded, then a command such as:
systemctl status mysqld || systemctl restart mysqld
will do the trick of re-starting the process. You could cron that:
* * * * * systemctl status mysqld || systemctl restart mysqld
However, in the case that mysql is loaded, but the service is not active, your cron will do nothing. So, you should use a more detailed command such as:
* * * * * systemctl is-active --quiet mysqld || systemctl restart mysqld
In this case, if the service is loaded but inactive such as the state that a DOS attack can leave your mysql service, the command will also restart mysql. Using the --quiet flag just specifies the command only to return a status code, not output anything to the screen. If you ommit the --quiet flag you will see a status output of either active or inactive.
You may also create some swap space to add more available RAM resources to your server such as:
sudo dd if=/dev/zero of=/swapfile count=2096 bs=1MiB
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon --show
swapon --summary
free -h

I think the problem is you have many parallel connections to your database which is causing this problem. The problem is not with table, problem is with architecture around it.

Related

Mac Big Sur MariaDB will not run

MariaDB has worked fine but is now failing to run on boot up. I have uninstalled and it then reinstalled it and this does not fix anything.
Here is the output from mysql.server.start
mysql.server start
Starting MariaDB
.210913 10:08:11 mysqld_safe Logging to '/usr/local/var/mysql/xxxx-MacBookPro.local.err'.
210913 10:08:11 mysqld_safe Starting mariadbd daemon with databases from /usr/local/var/mysql
/usr/local/bin/mysql.server: line 264: kill: (4944) - No such process
ERROR!
This is what I get from brew info mariadb
mariadb: stable 10.6.4 (bottled)
Drop-in replacement for MySQL
https://mariadb.org/
Conflicts with:
mariadb-connector-c (because both install `mariadb_config`)
mysql (because mariadb, mysql, and percona install the same binaries)
mytop (because both install `mytop` binaries)
percona-server (because mariadb, mysql, and percona install the same binaries)
/usr/local/Cellar/mariadb/10.6.4 (902 files, 183MB) *
Poured from bottle on 2021-09-13 at 09:49:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mariadb.rb
License: GPL-2.0-only
==> Dependencies
Build: bison ✘, cmake ✘, pkg-config ✘
Required: groonga ✔, openssl#1.1 ✔, pcre2 ✔
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
MySQL is configured to only allow connections from localhost by default
To have launchd start mariadb now and restart at login:
brew services start mariadb
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Analytics
install: 13,312 (30 days), 41,010 (90 days), 166,455 (365 days)
install-on-request: 13,289 (30 days), 40,949 (90 days), 165,680 (365 days)
build-error: 0 (30 days)
Here is what I get from brew services list
dnsmasq stopped
httpd error xxxx /usr/local/opt/httpd/homebrew.mxcl.httpd.plist
mariadb xxxx /usr/local/opt/mariadb/homebrew.mxcl.mariadb.plist
mysql#5.7 xxxx /usr/local/opt/mysql#5.7/homebrew.mxcl.mysql#5.7.plist
nginx stopped
php#5.6 stopped
php#7.0 stopped
php#7.3 stopped
php#7.4 stopped
The mac is serving up PHP successfully which throws a "Connection Refused" error when the code tries to talk to the database. So, I don't really understand the httpd error if apache appears to be operating.
Here is the contents of the err log (thank you DanBlack)
This is from the /usr/local/var/mysql/xxxx-MacBookPro.local.err
2021-09-16T15:30:12.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/XXXX-MacBookPro.local.pid ended
210916 17:30:13 mysqld_safe Starting mariadbd daemon with databases from /usr/local/var/mysql
2021-09-16 17:30:13 0 [Note] /usr/local/opt/mariadb/bin/mariadbd (server 10.6.4-MariaDB) starting as process 33244 ...
2021-09-16 17:30:13 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
/usr/local/opt/mariadb/bin/mariadbd: Please consult the Knowledge Base to find out how to run mysqld as root!
2021-09-16 17:30:13 0 [ERROR] Aborting
210916 17:30:13 mysqld_safe mysqld from pid file /usr/local/var/mysql/XXXX-MacBookPro.local.pid ended
2021-09-16T15:30:21.6NZ mysqld_safe Logging to '/usr/local/var/mysql/XXXX-MacBookPro.local.err'.
2021-09-16T15:30:21.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2021-09-16T15:30:21.651835Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-16T15:30:21.652151Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-09-16T15:30:21.652197Z 0 [Note] /usr/local/opt/mysql#5.7/bin/mysqld (mysqld 5.7.35) starting as process 33337 ...
2021-09-16T15:30:21.655210Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2021-09-16T15:30:21.656555Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-09-16T15:30:21.656576Z 0 [Note] InnoDB: Uses event mutexes
2021-09-16T15:30:21.656585Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-09-16T15:30:21.656593Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-09-16T15:30:21.658530Z 0 [Note] InnoDB: Number of pools: 1
2021-09-16T15:30:21.658624Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-09-16T15:30:21.659813Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-09-16T15:30:21.668320Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-09-16T15:30:21.719277Z 0 [ERROR] InnoDB: Only one log file found.
2021-09-16T15:30:21.719324Z 0 [ERROR] InnoDB: Plugin initialization aborted with error not found
2021-09-16T15:30:22.233348Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-09-16T15:30:22.233372Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-09-16T15:30:22.233382Z 0 [ERROR] Failed to initialize builtin plugins.
2021-09-16T15:30:22.233390Z 0 [ERROR] Aborting
2021-09-16T15:30:22.233402Z 0 [Note] Binlog end
2021-09-16T15:30:22.233465Z 0 [Note] Shutting down plugin 'CSV'
2021-09-16T15:30:22.233770Z 0 [Note] /usr/local/opt/mysql#5.7/bin/mysqld: Shutdown complete
This keeps repeating every few seconds.
However, I can now connect to the localhost mysql server and run things using mysql databases # 127.0.0.1 having deleted /usr/local/var/mysql/ib_logfile0
Ran into the same problem. Mariadb was conflicting with a previous mysql installation on my M1 mac.
Removed /opt/homebrew/var/mysql/ folder and reinstalled mariadb. Works fine now.

Getting error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed" when starting MySQL

I found many similar question on Stackoverflow but didn't get the exact error solution.
My issue is when starting MySQL service on one of the Dedicated Centos 6.5 machine, I am getting error :
141018 05:13:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
141018 5:13:47 [Warning] Can't create test file /var/lib/mysql/ip-184-168-73-83.lower-test
141018 5:13:47 [Warning] Can't create test file /var/lib/mysql/ip-184-168-73-83.lower-test
/usr/libexec/mysqld: Can't create/write to file '/tmp/ibkTWnhE' (Errcode: 28)
141018 5:13:48 InnoDB: Error: unable to create temporary file; errno: 28
141018 5:13:48 [ERROR] Plugin 'InnoDB' init function returned error.
141018 5:13:48 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
141018 5:13:48 [ERROR] Can't start server : Bind on unix socket: No space left on device
141018 5:13:48 [ERROR] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
141018 5:13:48 [ERROR] Aborting
141018 5:13:48 [Note] /usr/libexec/mysqld: Shutdown complete
141018 05:13:48 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Here are free command status:
free -m
total used free shared buffers cached
Mem: 3743 3631 111 0 2705 21
-/+ buffers/cache: 905 2838
Swap: 2047 0 2047
This error also happens when your Database data is corrupt. You may fix this issue by moving your Db data files (ib_logfile0 and ib_logfile1) mentioned below to another location. ib_logfile0 and ib_logfile1 are system tablespace for the InnoDB infrastructure. These files contains several classes for information vital for InnoDB. You may read about these files here.
Before following below steps please keep a copy of files (ib_logfile0 and ib_logfile1) so you may restore your data in case it is lost:
Follow below steps:
Login to server via SSH with root access.
Navigate to /var/lib/mysql.
If you see files like, ib_logfile0 and ib_logfile1, rename or move them to some other folder.
Stop and start the MySQL service by running sudo service mysql stop and sudo service mysql start
These files will be recreated after you restart the server and the issue will be fixed hopefully.
Thanks
I have the same problems, this my solution:
Add more RAM to the server
Decrease the value of innodb-buffer-pool size in the config file:
sudo nano /etc/mysql/my.cnf
innodb_buffer_pool_size = 10M
After save /etc/mysql/my.cnf.
Restart mysql service:
sudo service mysql restart
exit
This is frequently occurred issue. Do following -
delete/move out these "aria_log_contro, ib_logfile0, ib_logfile1, ib_data1" files from location "..\xampp\mysql\data" and also from "..\xampp\mysql\backup".
stop and start apache server and mysql form xampp control panel
This should fix the issue; actually it worked for me.
NOTE: THIS IS GOING TO RESET THE DB IN MANY CASES BE VERY CAREFUL
Changing the values of innodb_buffer_pool_size and innodb_log_file_size didn't work for me.
Moving ib_logfile0 and ib_logfile1 files didn't help either.
What did help was:
> service mysql stop
Edit my.cfg and add innodb_force_recovery = 1
> service mysql start
> service mysql stop
Comment the innodb_force_recovery = 1 line.
> service mysql start
And voilá. (I should note that I have no idea if this involves any data loss or not)
Although late but putting answer here so that solution that helped me can help someone. I took following steps:
Added more RAM to sever
Decrease the value of innodb-buffer-pool size
Set innodb_log_file_size
Restart mysql
Example of addition to my.cnf:
innodb_buffer_pool_size = 10M
innodb_log_file_size = 1000M
After few unsuccess hours, i checked the disk space... and was full...
I was getting below mysql error log:-
[Note] Plugin 'FEDERATED' is disabled.
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Using Linux native AIO
InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
InnoDB: Completed initialization of buffer pool
InnoDB: Fatal error: cannot allocate memory for the buffer pool
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
[Note] /usr/libexec/mysqld: Shutdown complete
I found out there are two solutions which are:-
1)Set innodb_log_file_size equal to the actual size of the existing InnoDB log files.
To see what size of innoDB log allocated, login mysql and enter following cmd:-
SHOW GLOBAL VARIABLES LIKE 'innodb_log_file_size';
Expected result example:- 5242880
After that, insert that value in my.cnf:-
vi /etc/my.cnf
innodb_log_file_size =5242880
2)Rename or move both the ./ib_logfile0 and ./ib_logfile1 files, and then start the MySQL server.This normally will be located at /var/lib/mysql. After start mysql, it create new innoDB log file and restore possible half-written data from the file of .ibd.
The expexted mysql log example:-
InnoDB: Database physically writes the file full: wait...
161216 9:58:54 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
161216 9:58:54 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
161216 9:58:54 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
161216 9:58:54 InnoDB: Waiting for the background threads to start
161216 9:58:55 InnoDB: 5.5.50 started; log sequence number 1589772
161216 9:58:55 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
161216 9:58:55 [Note] - '0.0.0.0' resolves to '0.0.0.0';
161216 9:58:55 [Note] Server socket created on IP: '0.0.0.0'.
161216 9:58:55 [Note] Event Scheduler: Loaded 0 events
161216 9:58:55 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.50' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL) by Remi
References:-
JUSTIN KULESZA (2011). MySQL: Failed Registration of InnoDB as a Storage Engine. Available at: https://spin.atomicobject.com/2011/05/09/mysql-failed-registration-of-innodb-as-a-storage-engine/.
RolandoMySQLDBA (2014). MySQL my.cnf: innodb_log_file_size is missing. Available at: https://dba.stackexchange.com/questions/75688/mysql-my-cnf-innodb-log-file-size-is-missing/158325#158325
Changing the Number or Size of InnoDB Redo Log Files. Available at: http://dev.mysql.com/doc/refman/5.7/en/innodb-data-log-reconfiguration.html
Nothing was working with reinstalls, removes, and others (I had no data to keep, not a fix; more of a data destruction process, big caveat there):
1005 mysql_install_db
1007 /usr/bin/mysqld_safe --datadir='/var/lib/mysql
1008 /usr/bin/mysqld_safe --datadir='/var/lib/mysql' (^z)
1009 bg
1010 mysql
1011 mysql_secure_installation
1012 mysql
1013 mysql -p
And viola; actually usable database.
for me the solution was to change the config to add
innodb_use_native_aio = 0
in mysql config
Just move this log file (ib_logfile0) to some other place for safer side and start the mysql services it worked for me.
I also met the same issue when restore a backup set made via innobackupex to a new instance. Finally ,the root cause is innodb_log_file_size doesn't match original instance that take the backup, and fix steps by steps like below:
Get innodb_log_file_size value from oragin instance via below command:
mysql uroot -ppasswd -NBe "show global variables like 'innodb_log_file_size';"
Modify the /etc/my.cnf of new instance with last get value:
vim /etc/my.cnf
Restart mysqld via :
systemctl restart mysqld

MariaDB 10 CentOS 7 moving datadir woes

Brand new "minimal" install of CentOS 7 along with MariaDB 10. I have an additional mounted mirrored volume that I want to use for the datadir. Startup sequence is fine and completes normally when my.cnf [mysqld] is commented out. I've copied the data..
sudo cp -R -p /var/lib/mysql/* /mnt/mysql/
The permissions are identical to those of the original. The volume is in /etc/fstab and mounts fine
/dev/sdb1 /mnt/mysql xfs defaults 0 0
[root#femur mysql]# ls -la
total 110632
drwxr-xr-x. 5 mysql mysql 4096 Oct 20 15:27 .
drwxr-xr-x. 3 root root 18 Oct 16 16:46 ..
-rw-rw----. 1 mysql mysql 16384 Oct 20 15:27 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Oct 20 15:27 aria_log_control
-rw-r-----. 1 mysql root 7005 Oct 20 13:49 femur.err
-rw-rw----. 1 mysql mysql 12582912 Oct 20 15:27 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Oct 20 15:27 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Oct 20 12:21 ib_logfile1
-rw-rw----. 1 mysql mysql 0 Oct 20 12:22 multi-master.info
drwx--x--x. 2 mysql mysql 4096 Oct 20 12:21 mysql
drwx------. 2 mysql mysql 4096 Oct 20 13:37 performance_schema
drwxr-xr-x. 2 mysql mysql 6 Oct 20 12:21 test
this is in my.cnf
!includedir /etc/my.cnf.d
[mysqld]
log_error = /var/log/mysql-error.log
user = mysql
datadir = /mnt/mysql
socket = /mnt/mysql/mysql.sock
This is what I get when I try to start it...
'[root#femur mysql]# sudo systemctl start mysql.service
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.'
Neither of those two files says much, but this is in /var/log/mysql-error.log
141020 16:07:09 mysqld_safe Starting mysqld daemon with databases from /mnt/mysql
141020 16:07:09 [Warning] Can't create test file /mnt/mysql/femur.lower-test
141020 16:07:09 [Note] InnoDB: Using mutexes to ref count buffer pool pages
141020 16:07:09 [Note] InnoDB: The InnoDB memory heap is disabled
141020 16:07:09 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
141020 16:07:09 [Note] InnoDB: Memory barrier is not used
141020 16:07:09 [Note] InnoDB: Compressed tables use zlib 1.2.7
141020 16:07:09 [Note] InnoDB: Using Linux native AIO
141020 16:07:09 [Note] InnoDB: Using CPU crc32 instructions
141020 16:07:09 [Note] InnoDB: Initializing buffer pool, size = 128.0M
141020 16:07:09 [Note] InnoDB: Completed initialization of buffer pool
2014-10-20 16:07:09 7f6cb59c9880 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
141020 16:07:09 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
141020 16:07:09 [ERROR] InnoDB: The system tablespace must be writable!
141020 16:07:09 [ERROR] Plugin 'InnoDB' init function returned error.
141020 16:07:09 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
141020 16:07:09 [ERROR] mysqld: File '/mnt/mysql/aria_log_control' not found (Errcode: 13 "Permission denied")
141020 16:07:09 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/mnt/mysql/aria_log_control'
141020 16:07:09 [ERROR] Plugin 'Aria' init function returned error.
141020 16:07:09 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
141020 16:07:09 [Note] Plugin 'FEEDBACK' is disabled.
141020 16:07:09 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
141020 16:07:09 [ERROR] Unknown/unsupported storage engine: InnoDB
141020 16:07:09 [ERROR] Aborting
141020 16:07:09 [Note] /usr/sbin/mysqld: Shutdown complete
141020 16:07:09 mysqld_safe mysqld from pid file /mnt/mysql/femur.pid ended
http://www.reddit.com/r/linuxadmin/comments/2ebhpf/adventures_in_moving_mariadb_data_folder/ helped a bit, but I wasn't able to get it to work.
Any help would be greatly appreciated.
The issue is indeed SELinux; you need to do three things before MariaDB / MySQL will start on CentOS 7:
Ensure the user:group is mysql:mysql
Set the SELinux tag to mysqld_db_t
Set the SELinux user to system_u
This is as simple as:
chcon -Rt mysqld_db_t /database/db
chcon -Ru system_u /database/db
chown -R mysql:mysql /database/db
The whole thing I needed to do after plugging in a disk is below:
cfdisk /dev/sdb
pvcreate /dev/sdb1
vgcreate database /dev/sdb1
lvcreate -l 100%FREE -n db database
mkfs.ext4 /dev/database/db
mkdir /database
mount /database
mkdir /database/db
chcon -Rt mysqld_db_t /database/db
chcon -Ru system_u /database/db
chown -R mysql:mysql /database/db
systemctl start mariadb
Well that was interesting...
It turns out, that CentOS 7 "minimal" installs SELinux, which apparently was preventing mysql from writing to the mounted mirrored set. I was looking for security items that I might not have thought about and found it right there in the docs. I had previously thought (obviously erroneously) that SELinux was a distribution, not a module. Once I ran the test to see if it was there....
getenforce
I temporarily disabled it to test.
setenforce 0
Finally, I was able to start MariaDB with the directory in the mirrored set as the datadir and no errors. To make this change permanent (because this server is behind a firewall), in /etc/selinux/config, I made
- SELINUX=enforcing
+ SELINUX=disabled
I hope this helps someone else. Have a great day!
I found this step by step guide working for me: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/sect-Managing_Confined_Services-MariaDB-Configuration_Examples.html
You must install:
yum install policycoreutils-python
Guide:
View the SELinux context of the default database location for mysql:
~]# ls -lZ /var/lib/mysql
drwx------. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql
This shows mysqld_db_t which is the default context element for the location of database files. This context will have to be manually applied to the new database location that will be used in this example in order for it to function properly.
Stop the mysqld daemon:
~]# systemctl stop mariadb.service
Create a new directory for the new location of the database(s). In this example, /mysql/ is used:
~]# mkdir -p /mysql
Copy the database files from the old location to the new location:
~]# cp -R /var/lib/mysql/* /mysql/
Change the ownership of this location to allow access by the mysql user and group. This sets the traditional Unix permissions which SELinux will still observe:
~]# chown -R mysql:mysql /mysql
Run the following command to see the initial context of the new directory:
~]# ls -lZ /mysql
drwxr-xr-x. mysql mysql unconfined_u:object_r:usr_t:s0 mysql
The context usr_t of this newly created directory is not currently suitable to SELinux as a location for MariaDB database files. Once the context has been changed, MariaDB will be able to function properly in this area.
Open the main MariaDB configuration file /etc/my.cnf with a text editor and modify the datadir option so that it refers to the new location. In this example the value that should be entered is /mysql:
[mysqld]
datadir=/mysql
Save this file and exit.
Start mysqld. The service should fail to start, and a denial message will be logged to the /var/log/messages file:
~]# systemctl start mariadb.service
Job for mariadb.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.
However, if the audit daemon is running and with him the setroubleshoot service, the denial will be logged to the /var/log/audit/audit.log file instead:
SELinux is preventing /usr/libexec/mysqld "write" access on /mysql. For complete SELinux messages. run sealert -l b3f01aff-7fa6-4ebe-ad46-abaef6f8ad71
The reason for this denial is that /mysql/ is not labeled correctly for MariaDB data files. SELinux is stopping MariaDB from having access to the content labeled as usr_t. Perform the following steps to resolve this problem:
Run the following command to add a context mapping for /mysql/. Note that the semanageutility is not installed by default. If it missing on your system, install the policycoreutils-pythonpackage.
**~]# semanage fcontext -a -t mysqld_db_t "/mysql(/.*)?"**
This mapping is written to the /etc/selinux/targeted/contexts/files/file_contexts.local file:
~]# grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local
/mysql(/.*)? system_u:object_r:mysqld_db_t:s0
Now use the restorecon utility to apply this context mapping to the running system:
**~]# restorecon -R -v /mysql**
Now that the /mysql/ location has been labeled with the correct context for MariaDB, mysqldstarts:
~]# systemctl start mariadb.service
Confirm the context has changed for /mysql/:
~]$ ls -lZ /mysql
drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql
The location has been changed and labeled, and mysqld has started successfully. At this point all running services should be tested to confirm normal operation.

Running MySQL in a Docker container

So my ultimate end goal is to run a MySQL Docker container (say tutum/mysql from the public registry) and then link a Gitlab Docker container (say sameersbn/gitlab) to it where both containers use persistent storage.
However, I am stuck on the MySQL part. Every time I try and run a pre-made MySQL Docker container (mysql, tutum/mysql and sameersbn/mysql) as outlined below, I get the below output.
Steps
This is just one way of getting to the error message below.
docker.io pull tutum/mysql:latest
docker.io run -it tutum/mysql bash
Once attached to the new container run "/run.sh" (as per tutum/mysql dockerfile)
At this point a "Waiting for confirmation of MySQL service startup" message constantly repeats.
At this point if I cancel the "/run.sh" command and start MySQL myself I get the error message below.
Output:
root#1bbeb34f3491:/# mysqld
140730 4:49:04 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
140730 4:49:04 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140730 4:49:04 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
140730 4:49:04 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
140730 4:49:04 InnoDB: The InnoDB memory heap is disabled
140730 4:49:04 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140730 4:49:04 InnoDB: Compressed tables use zlib 1.2.8
140730 4:49:04 InnoDB: Using Linux native AIO
140730 4:49:04 InnoDB: Initializing buffer pool, size = 128.0M
140730 4:49:04 InnoDB: Completed initialization of buffer pool
140730 4:49:04 InnoDB: highest supported file format is Barracuda.
140730 4:49:04 InnoDB: Waiting for the background threads to start
140730 4:49:05 InnoDB: 5.5.37 started; log sequence number 1595675
140730 4:49:05 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
140730 4:49:05 [Note] - '0.0.0.0' resolves to '0.0.0.0';
140730 4:49:05 [Note] Server socket created on IP: '0.0.0.0'.
140730 4:49:05 [ERROR] Can't start server : Bind on unix socket: Permission denied
140730 4:49:05 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
140730 4:49:05 [ERROR] Aborting
140730 4:49:05 InnoDB: Starting shutdown...
140730 4:49:06 InnoDB: Shutdown completed; log sequence number 1595675
140730 4:49:06 [Note] mysqld: Shutdown complete
Addressing the errors
"Please run mysql_upgrade to create it" => run mysql_upgrade command which outputs
root#1bbeb34f3491:/# mysql_upgrade
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
FATAL ERROR: Upgrade failed
"Do you already have another mysqld server running on socket" => Nope. Running service mysql stop does nothing and running ps doesn't show mysqld. Running ls -a /var/run/mysqld/ suggests that the socket file doesn't exist.
No matter which MySQL container I try, eventually when I start MySQL the same error message came up. This almost certainly means there is something wrong with my setup which confuses me because I thought a Docker container, with no exposed ports or persistent storage, would be isolated from the system Docker is installed on?
I have also tried running a MySQL container with the -d flag then running a fresh ubuntu 14.04 container (docker.io run -it --link mysql:mysql ubuntu:14.04 bash) linked to it. On the Ubuntu container I installed mysql-client through apt-get and tried to connect to the MySQL container on the ip address in MYSQL_PORT_3306_TCP_ADDR but that doesn't work either.
Equally the problem might be that I do not understand how Docker works. If this is the case, can someone create a set of steps that uses one of the MySQL containers on the Docker index and then link a container to it that can connect. This will also help to see whether there is something wrong with my Docker installation (or some other unknown problem that is causing this issue).
My host system is running Ubuntu 14.04 and Docker was installed through apt-get and is version 0.9.1.
I wasn't quite sure what to put in this explanation because the problem seems quite weird to me. If there is anything I have missed please ask and I will add it for you.
Thanks,
JamesStewy
This works for me:
docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql
No need to run the script from bash, no need for anything clever.

Error establishing a database connection

I have a wordpress site on a VPS running Debian 7 that was working fine when I last visited it and I've made no changes since, but now when I visit the site it says: Error establishing a database connection. It also gives the same error in the admin portal.
I had not changed the password, domain, IP, or anything and checked the wp-config.php and everything in it is accurate.
I logged into my VPS as root and tried to log into mysql to check to see if wordpress was still a user, but it couldn't locate the socket:
root#debian7:~# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
So I tried restarting the mysqld and got:
root#debian7:~# /etc/init.d/mysql restart
[ ok ] Stopping MySQL database server: mysqld.
[FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
When I try to run mysqld:
root#debian7:~# mysqld
131226 15:36:15 [Warning] Can't create test file /var/lib/mysql/debian7.lower-test
131226 15:36:15 [Warning] Can't create test file /var/lib/mysql/debian7.lower-test
131226 15:36:15 [Note] Plugin 'FEDERATED' is disabled.
131226 15:36:15 InnoDB: The InnoDB memory heap is disabled
131226 15:36:15 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131226 15:36:15 InnoDB: Compressed tables use zlib 1.2.7
131226 15:36:15 InnoDB: Using Linux native AIO
mysqld: Can't create/write to file '/tmp/ibRx51To' (Errcode: 30)
131226 15:36:15 InnoDB: Error: unable to create temporary file; errno: 30
131226 15:36:15 [ERROR] Plugin 'InnoDB' init function returned error.
131226 15:36:15 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
131226 15:36:15 [ERROR] Unknown/unsupported storage engine: InnoDB
131226 15:36:15 [ERROR] Aborting
131226 15:36:15 [Note] mysqld: Shutdown complete
So it seemed to be an access problem, so I checked the /var/lib/mysql directory
root#debian7:~# stat /var/lib/mysql
File: `/var/lib/mysql'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: fe00h/65024d Inode: 391599 Links: 6
Access: (0700/drwx------) Uid: ( 104/ mysql) Gid: ( 106/ mysql)
Access: 2013-12-10 15:58:56.401341180 -0500
Modify: 2013-12-10 15:58:56.241341172 -0500
Change: 2013-12-10 15:58:56.241341172 -0500
Birth: -
As you can see, mysql is the owner and has rwx access..
The logs are somehow empty so I can't figure out what happened. I'm not familiar with troubleshooting these kinds of things though. So I could be making novice mistakes.
I'm just trying to get my wordpress site back and it seems the database dsiconnected on its own and the server wont restart. Any ideas?
More:
My /etc/mysql/my.cnf file contains these relevant lines:
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
bind-address = 127.0.0.1
Okay, after troubleshooting a while, it turned out that the entire file system is read-only. I tried making new files and in each case it says it can't cause "Read-only filesystem"
It seems to be a bad image or some sort of change my VPS provider made. So I'll be contacting them.