restore physical backups for mysql using xtrabackup - mysql

I backup mysql database, and then try to restore it in a later version using xtrabackup, mysql service can't start up.
old mysql version:5.0.90;
new version:5.5.31
Recovery Steps:
innobackupex --use-memory=4G --apply-log /data/backups/2010-03-13_02-42-44/
innobackupex --copy-back /data/backups/2010-03-13_02-42-44/
The second step shows that xtrabackup restored mysql database completely.
sudo mysql service start mysql
I try to start mysql service, it shows "Job failed to start".i check the permission of these database files,as you can see below.
-rw-r--r-- 1 mysql mysql 209715200 7月 11 06:02 ibdata1
-rw-r--r-- 1 mysql mysql 1048576000 7月 11 06:03 ib_logfile0
-rw-r--r-- 1 mysql mysql 1048576000 7月 11 06:03 ib_logfile1
drwxr-xr-x 2 mysql mysql 4096 7月 11 06:02 mysql
drwxr-xr-x 2 mysql mysql 12288 7月 11 06:02 sp5084afbe48ce9
drwxr-xr-x 2 mysql mysql 4096 7月 11 06:02 test
-rw-r--r-- 1 mysql mysql 52 7月 11 06:02 xtrabackup_binlog_pos_innodb
-rw-r--r-- 1 mysql mysql 76 7月 11 06:02 xtrabackup_slave_info
This is the error:
InnoDB: Error: log file ./ib_logfile0 is of different size 0 1048576000 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
130711 6:08:56 [ERROR] Plugin 'InnoDB' init function returned error.
130711 6:08:56 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130711 6:08:56 [ERROR] Unknown/unsupported storage engine: InnoDB
130711 6:08:56 [ERROR] Aborting
130711 6:08:56 [Note] /usr/sbin/mysqld: Shutdown complete

Check the /etc/mysql/my.cnf and look for the
innodb_log_file_size = 5M
and change that to
innodb_log_file_size = 1000M
Cause 1048576000/1024/1024=1000 and that is how much is InnoDB engine is expecting for log file size.
similar problem

Related

vagrant shared storage - docker container mysql - persistent volume - not coming up

I tried multiple times with no luck and the results are going nowhere.
My set up is something like this:
windows 10 host
virtual box latest version
guest VM is ubuntu latest minimal (command line)
using vagrant to create VMs and share folders between host and guest VM
My code, Dockerfile, and Docker-compose files are saved in shared folder say (/vagrant/test) so I can easily access them from the Windows host.
From guest VM: (file permissions)
vagrant#dev-env-testing:/vagrant/test$ ll
drwxrwxrwx 1 vagrant vagrant 4096 Apr 19 12:33 ./
drwxr-xr-x 23 root root 4096 Apr 14 12:50 ../
drwxrwxrwx 1 vagrant vagrant 0 Apr 14 10:30 .vagrant/
-rwxrwxrwx 1 vagrant vagrant 1072 Apr 14 13:36 Vagrantfile*
-rwxrwxrwx 1 vagrant vagrant 0 Apr 19 11:23 a*
drwxrwxrwx 1 vagrant vagrant 0 Apr 19 12:33 code/
drwxrwxrwx 1 vagrant vagrant 4096 Apr 19 12:28 mysql-data/
-rwxrwxrwx 1 vagrant vagrant 0 Apr 19 12:29 mysqlcontainer_bug_sharefolder.txt*
I also added the user "vagrant" in the group: 999(systemd-coredump)
vagrant#dev-env-testing:/vagrant$ id
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lxd),997(docker),999(systemd-coredump)
For testing I'm using this command to create a container:
docker run -d --name=test-mysql4 -e MYSQL_ROOT_PASSWORD=mypassword -p 6604:3306 -v /vagrant/mysql-data:/var/lib/mysql MySQL
here, I'm trying to create a persistent volume (mounted on a host shared folder /vagrant/mysql-data) for my_sql container but the container creation is failing.
Scenario 1:
/vagrant/mysql-data: has no data in this folder.
docker logs test-mysql4
2021-04-19 12:28:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-19 12:28:37+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-04-19 12:28:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-19 12:28:37+00:00 [Note] [Entrypoint]: Initializing database files
2021-04-19T12:28:37.465722Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.23) initializing of server in progress as process 43
2021-04-19T12:28:37.472616Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2021-04-19T12:28:37.478227Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-04-19T12:28:41.252791Z 0 [ERROR] [MY-012592] [InnoDB] Operating system error number 95 in a file operation.
2021-04-19T12:28:41.252961Z 0 [ERROR] [MY-012596] [InnoDB] Error number 95 means 'Operation not supported'
2021-04-19T12:28:41.253274Z 0 [ERROR] [MY-012646] [InnoDB] File ./undo_001: 'Linux aio' returned OS error 195. Cannot continue operation
2021-04-19T12:28:41.253413Z 0 [ERROR] [MY-012981] [InnoDB] Cannot continue operation.
or I get this error
Scenario 2:
/vagrant/mysql-data: has below files,
/vagrant/mysql-data$ ls
'#ib_16384_0.dblwr' '#ib_16384_1.dblwr' ib_logfile1 ib_logfile101
ibdata1 undo_001 undo_002 undo_1_trunc.log undo_2_trunc.log
2021-04-19 12:25:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-19 12:25:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-04-19 12:25:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.
2021-04-19 12:25:20+00:00 [Note] [Entrypoint]: Initializing database files
2021-04-19T12:25:20.641591Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.23) initializing of server in progress as process 43
2021-04-19T12:25:20.645008Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-04-19T12:25:20.645019Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2021-04-19T12:25:20.645069Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-04-19T12:25:20.645195Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.23) MySQL Community Server - GPL.
vagrant#rma-dev-env-testing:/vagrant/mysql-data$ ls
Any help is greatly appreciated.
Thanks in advance

MySQL won't start - error: su: warning: cannot change directory to /nonexistent: No such file or directory

New to development & self-teaching (thanks Covid) so this could be sloppy :( sorry...
let me start off by saying I don't care about the data in the database - if it is easier to wipe it and start fresh, I'm good with that (don't know how to do that but I'm ok with it)
Not sure what caused the issue but one day MySQL wouldn't start. Using service MySQL Restart fixed it... two days later it happened again with this error
sarcasticsnark#LB-HP-LT:~/Projects/FMS$ sudo service mysql start
* Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory
I've tried a bit of "solutions"
I've tried restarting MySQL
I gave myself file permissions to the mysql files (then attempted to reverse that)
I've moved the MySQL directory (then reversed it - hence the copy of the folder "mysql" named "mysql2" below)
My files now look like this and I'm not sure I got the permissions quite right.
sarcasticsnark#LB-HP-LT:/var/lib$ ls
AccountsService command-not-found fwupd logrotate mysql mysql2, private systemd ucf usbutils
PackageKit dbus git man-db mysql-files pam python tpm unattended-upgrades vim
apt dhcp initramfs-tools mecab mysql-keyring plymouth snapd ubuntu-advantage update-manager
boltd dpkg landscape misc mysql-upgrade polkit-1 sudo ubuntu-release-upgrader update-notifier
sarcasticsnark#LB-HP-LT:/var/lib$ cd mysql
sarcasticsnark#LB-HP-LT:/var/lib/mysql$ ls
'#ib_16384_0.dblwr' TestingGround_development binlog.000009 binlog.000013 binlog.000017 client-cert.pem mysql.ibd server-cert.pem undo_002
'#ib_16384_1.dblwr' TestingGround_test binlog.000010 binlog.000014 binlog.index client-key.pem performance_schema server-key.pem
'#innodb_temp' auto.cnf binlog.000011 binlog.000015 ca-key.pem debian-5.7.flag private_key.pem sys
FMS_development binlog.000008 binlog.000012 binlog.000016 ca.pem mysql public_key.pem undo_001
I've re-initialized MySQL (when not running sudoku it errors the below)
2020-07-20T02:29:41.520132Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 4096 (requested 8161)
2020-07-20T02:29:41.520141Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 1967 (requested 4000)
2020-07-20T02:29:41.520561Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20-0ubuntu0.20.04.1) initializing of server in progress as process 2570
2020-07-20T02:29:41.522888Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2020-07-20T02:29:41.522921Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error.log' for error logging: Permission denied
2020-07-20T02:29:41.523139Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-07-20T02:29:41.523187Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-07-20T02:29:41.523313Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20-0ubuntu0.20.04.1) (Ubuntu).
/var/log/mysql - does exist and the permissions for it are:
-rw-r----- 1 mysql adm 62273 Jul 19 19:36 error.log
Here is mysql/error.log
2020-07-20T01:50:07.952988Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2020-07-20T01:50:07.986416Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2020-07-20T01:50:08.000603Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2020-07-20T01:50:08.000610Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
2020-07-20T01:50:08.262922Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20-0ubuntu0.20.04.1) starting as process 1608
2020-07-20T01:50:08.281623Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-20T01:50:08.322464Z 1 [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
2020-07-20T01:50:08.322818Z 1 [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
2020-07-20T01:50:08.322947Z 1 [ERROR] [MY-012594] [InnoDB] If you are installing InnoDB, remember that you must create directories yourself, InnoDB does not create them.
2020-07-20T01:50:08.323017Z 1 [ERROR] [MY-012646] [InnoDB] File ./ibdata1: 'open' returned OS error 71. Cannot continue operation
2020-07-20T01:50:08.323105Z 1 [ERROR] [MY-012981] [InnoDB] Cannot continue operation.
2020-07-20T01:50:08.972320Z mysqld_safe mysqld from pid file /var/lib/mysql/LB-HP-LT.pid ended
And the permissions for /var/lib/mysql
sarcasticsnark#LB-HP-LT:/var/lib/mysql$ cd /var/lib
sarcasticsnark#LB-HP-LT:/var/lib$ sudo ls -l mysql
[sudo] password for sarcasticsnark:
total 58048
-rw-r----- 1 mysql mysql 196608 Jul 19 16:34 '#ib_16384_0.dblwr'
-rw-r----- 1 mysql mysql 8585216 Jul 11 22:54 '#ib_16384_1.dblwr'
drwxr-x--- 2 mysql mysql 4096 Jul 19 16:35 '#innodb_temp'
drwxr-x--- 2 mysql mysql 4096 Jul 15 18:06 FMS_development
drwxr-x--- 2 mysql mysql 4096 Jun 20 09:04 TestingGround_development
drwxr-x--- 2 mysql mysql 4096 Jun 22 20:07 TestingGround_test
-rw-r----- 1 mysql mysql 56 Jun 10 17:43 auto.cnf
-rw-r----- 1 mysql mysql 210461 Jul 15 17:01 binlog.000008
-rw-r----- 1 mysql mysql 179 Jul 15 17:30 binlog.000009
-rw-r----- 1 mysql mysql 156 Jul 15 17:43 binlog.000010
-rw-r----- 1 mysql mysql 2798 Jul 19 15:55 binlog.000011
-rw-r----- 1 mysql mysql 179 Jul 19 15:56 binlog.000012
-rw-r----- 1 mysql mysql 179 Jul 19 16:11 binlog.000013
-rw-r----- 1 mysql mysql 179 Jul 19 16:25 binlog.000014
-rw-r----- 1 mysql mysql 179 Jul 19 16:27 binlog.000015
-rw-r----- 1 mysql mysql 179 Jul 19 16:27 binlog.000016
-rw-r----- 1 mysql mysql 179 Jul 19 16:34 binlog.000017
-rw-r----- 1 mysql mysql 160 Jul 19 16:27 binlog.index
-rw------- 1 mysql mysql 1680 Jun 10 17:43 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 Jun 10 17:43 ca.pem
-rw-r--r-- 1 mysql mysql 1112 Jun 10 17:43 client-cert.pem
-rw------- 1 mysql mysql 1680 Jun 10 17:43 client-key.pem
-rw-r--r-- 1 mysql mysql 0 Jun 12 15:54 debian-5.7.flag
drwxr-xr-x 2 mysql mysql 4096 Jun 10 17:43 mysql
-rw-r----- 1 mysql mysql 25165824 Jul 19 16:28 mysql.ibd
drwxr-x--- 2 mysql mysql 4096 Jun 10 17:43 performance_schema
-rw------- 1 mysql mysql 1680 Jun 10 17:43 private_key.pem
-rw-r--r-- 1 mysql mysql 452 Jun 10 17:43 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 Jun 10 17:43 server-cert.pem
-rw------- 1 mysql mysql 1676 Jun 10 17:43 server-key.pem
drwxr-x--- 2 mysql mysql 4096 Jun 10 17:43 sys
-rw-r----- 1 mysql mysql 12582912 Jul 19 16:34 undo_001
-rw-r----- 1 mysql mysql 12582912 Jul 19 16:34 undo_002
mysql user is looking for a home directory, which seems to have not been assigned.
To do that, you can execute:
sudo systemctl stop mysql.service
sudo usermod -d /var/lib/mysql/ mysql
sudo systemctl start mysql.service
or
sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
Based on a response found here

Reinstall mysql-server after upgrade to Ubuntu 18.04 - errors

Mysql needed to be reinstalled after I upgraded to Ubuntu 18.04. I did 'sudo service mysqld stop' before the upgrade, and then the cleanup step must have removed mysql server. When it wasn't found I did:
sudo apt-get remove mysql-server
sudo apt-get install mysql-server
...
Setting up mysql-server-5.7 (5.7.22-0ubuntu18.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
mysqld: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
Please enable --log-error option or set appropriate redirections for standard output and/or standard error in daemon mode.
Warning: Unable to start the server. Please restart MySQL and run mysql_upgrade to ensure the database is ready for use.
mysqld: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
Please enable --log-error option or set appropriate redirections for standard output and/or standard error in daemon mode.
Warning: Unable to start the server.
...
I then ran 'systemctl status mysql.service' which reported this:
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.828124Z 0 [ERROR] InnoDB: Operating system error number 2 in a file oper
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.828132Z 0 [ERROR] InnoDB: The error means the system cannot find the pat
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.828140Z 0 [ERROR] InnoDB: Could not find a valid tablespace file for `my
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.828199Z 0 [Warning] InnoDB: Cannot calculate statistics for table `mysql
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.828232Z 0 [ERROR] Can't open and lock privilege tables: Tablespace is mi
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.846964Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180719 11:21:4
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.934673Z 0 [Note] Event Scheduler: Loaded 0 events
Jul 19 11:21:49 steve-VAIO mysqld[6106]: 2018-07-19T18:21:49.934950Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Jul 19 11:21:49 steve-VAIO mysqld[6106]: Version: '5.7.22-0ubuntu18.04.1' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu
Jul 19 11:21:49 steve-VAIO systemd[1]: Started MySQL Community Server.
mysqld is running and my databases are available, but I'm sure this will bite me again when it updates. phpMyAdmin shows the mysql database, which seems healthy. At the top of the list of databases is one called '#mysql50#mysql.bkp'.
Any suggestions for cleaning this up?
After suggestion to run mysql_upgrade, I did:
steve#steve-VAIO:~/workspace/JavascriptCourse$ mysql_upgrade -u root -p
mysql_upgrade: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
Enter password:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
mysql_upgrade: [ERROR] 1812: Tablespace is missing for table `mysql`.`plugin`.
So I'll hunt for a fix for this table's tablespace.

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.

MYSQL Unable to start the service

I just downloaded MySQL 5.0.9 source code and build and installed as root user:
./configure
./make
./make install
Now I am trying to bring up mysqld but the error says:
[root libexec]# ./mysqld
120718 7:37:09 [ERROR] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
120718 7:37:09 [ERROR] Aborting
120718 7:37:09 [Note] ./mysqld: Shutdown complete
[root libexec]#
Note that I did all my activity as a root user and am trying to start the service for the very first time itself?
I did what user868766 stated below but was unable to successfully execute last command. However now I get something else while trying to invoke it directly:
BTW how do we set the MySQL root password?
[root libexec]# ./mysqld
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
120718 7:52:35 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
120718 7:52:35 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
120718 7:52:35 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...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
120718 7:52:35 InnoDB: Started; log sequence number 0 0
120718 7:52:35 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
I just ran as per info present in the link provided by user868766:
[root bin]# mysql_install_db
Note using command other than that was giving issues:
[root bin]# mysql_install_db -user=mysql -ldata=/opt/mysql/mysql/data
Installing MySQL system tables...
120718 8:35:00 [Warning] Ignoring user change to 'ser=mysql' because the user was set to 'mysql' earlier on the command line
120718 8:35:00 [Warning] Ignoring user change to 'ser=mysql' because the user was set to 'mysql' earlier on the command line
/usr/local/libexec/mysqld: File 'data=/opt/mysql/mysql/data' not found (Errcode: 2)
120718 8:35:00 [ERROR] Could not use data=/opt/mysql/mysql/data for logging (error 2). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
OK
Filling help tables...
120718 8:35:00 [Warning] Ignoring user change to 'ser=mysql' because the user was set to 'mysql' earlier on the command line
120718 8:35:00 [Warning] Ignoring user change to 'ser=mysql' because the user was set to 'mysql' earlier on the command line
/usr/local/libexec/mysqld: File 'data=/opt/mysql/mysql/data' not found (Errcode: 2)
120718 8:35:00 [ERROR] Could not use data=/opt/mysql/mysql/data for logging (error 2). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/bin/mysqladmin -u root password 'new-password'
/usr/local/bin/mysqladmin -u root -h idc-bldtool01 password 'new-password'
Alternatively you can run:
/usr/local/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local ; /usr/local/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[root bin]# ls -l /opt/mysql/mysql/data
total 0
However after this I am able to bring mysqld up:
[root libexec]# ./mysqld
InnoDB: Log scan progressed past the checkpoint lsn 0 36808
120718 8:37:22 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...
InnoDB: Doing recovery: scanned up to log sequence number 0 43655
120718 8:37:22 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
120718 8:37:23 InnoDB: Started; log sequence number 0 43655
120718 8:37:23 [Note] ./mysqld: ready for connections.
Version: '5.0.91' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
Now I am trying to setup the root password as hinter in the above console dump:
[root~]# /usr/local/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Enter current password for root (enter for none):
Aborting!
Cleaning up...
Please let me know how can I resolve the issue?
Thanks to user868766 I managed to resolve and able to bring up mysql and connect to it.
Please try this :
1. cd /var/lib/mysql
2. adduser mysql
3. chown mysql:mysql -R /var/lib/mysql
4. service mysqld restart
Please execute the command in given order it should help you.