将mariaDb数据库移动到主文件夹

安装后,我试图移动数据库位置在Fedora上:

# su # systemtcl stop mariadb # cp -rp /var/lib/mysql /home # chown mysql.mysql /home/mysql 

接下来,我正在编辑文件/etc/my.cnf.d/mariadb-server.cnf

 [mysqld] datadir=/var/lib/mysql/ socket=/var/lib/mysql.sock 

 [mysqld] datadir=/home/mysql/ socket=/home/mysql.sock 

然后

 # systemctl start mariadb Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details. 

所以

 systemctl status mariadb ● mariadb.service - MariaDB 10.0 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Wed 2016-06-29 17:51:18 CEST; 29s ago Process: 6488 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS) Process: 3103 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 6304 ExecStartPost=/usr/libexec/mysql-wait-ready $MAINPID (code=exited, status=1/FAILURE) Process: 6303 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=1/FAILURE) Process: 6259 ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS) Process: 6231 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 6303 (code=exited, status=1/FAILURE) Jun 29 17:51:17 123PUB-PC systemd[1]: Starting MariaDB 10.0 database server... Jun 29 17:51:17 123PUB-PC mysqld_safe[6303]: 160629 17:51:17 mysqld_safe Logging to '/var/log/maria...g'. Jun 29 17:51:17 123PUB-PC mysqld_safe[6303]: mkdir: impossible de créer le répertoire « /home/mysql…xiste Jun 29 17:51:17 123PUB-PC mysqld_safe[6303]: Fatal error Can't create database directory '/home/mys...ck' Jun 29 17:51:17 123PUB-PC systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE Jun 29 17:51:18 123PUB-PC systemd[1]: mariadb.service: Control process exited, code=exited status=1 Jun 29 17:51:18 123PUB-PC systemd[1]: Failed to start MariaDB 10.0 database server. Jun 29 17:51:18 123PUB-PC systemd[1]: mariadb.service: Unit entered failed state. Jun 29 17:51:18 123PUB-PC systemd[1]: mariadb.service: Failed with result 'exit-code'. Hint: Some lines were ellipsized, use -l to show in full. 

所以看起来mysql在home / mysql上没有写权限,但是:

 # ls -la /home/mysql drwxr-xr-x. 4 mysql mysql 4096 Jun 29 17:38 . drwxr-xr-x. 5 root root 4096 Jun 29 17:54 .. -rw-rw----. 1 mysql mysql 16384 Jun 29 17:38 aria_log.00000001 -rw-rw----. 1 mysql mysql 52 Jun 29 17:38 aria_log_control -rw-rw----. 1 mysql mysql 12582912 Jun 29 17:38 ibdata1 -rw-rw----. 1 mysql mysql 50331648 Jun 29 17:38 ib_logfile0 -rw-rw----. 1 mysql mysql 50331648 Jun 29 17:05 ib_logfile1 -rw-rw----. 1 mysql mysql 0 Jun 29 17:05 multi-master.info drwx------. 2 mysql mysql 4096 Jun 29 17:05 mysql -rw-r--r--. 1 mysql mysql 16 Jun 29 17:05 mysql_upgrade_info drwx------. 2 mysql mysql 4096 Jun 29 17:05 performance_schema 

我没有看到任何与主目录的差异。

那么接下来呢?

这是一个SELinux问题。 但要确保禁用执行testing。

testing

在您的服务器(仅限于root)中执行此操作以临时禁用SELinux

 # setenforce 0 

现在你可以启动服务器了

 # systemctl start mariadb 

使用mysql客户端连接,但首先修改文件/etc/my.cnf.d/client.cnf上的configuration以使用新的套接字文件。

 # # These two groups are read by the client library # Use it for options that affect all clients, but not the server # [client] socket=/home/mysql/mysql.sock # This group is not read by mysql client library, # If you use the same .cnf file for MySQL and MariaDB, # use it for MariaDB-only client options [client-mariadb] 

如果一切正常,那么你将能够连接到你新找的数据库。

停止服务器

 # systemctl stop mariadb 

SELinuxconfiguration永久解决scheme

SELinux可以防止mysqld在默认目录以外的任何目录下工作(读取,写入,访问)。
为了克服这个问题,你需要修改这个行为,SELinux授予你的新位置权限。

获取上下文。 列表可能有所不同,但应显示mysqld_db_t上下文。

 # ls -lZ /var/lib/mysql drwx------. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 mysql 

将获得的上下文( mysqld_db_t )添加到/home/mysql的映射中。

 # semanage fcontext -a -t mysqld_db_t "/home/mysql(/.*)?" 

应用上下文

 # restorecon -R -v /home/mysql 

检查是否应用上下文

 # grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local /home/mysql(/.*)? system_u:object_r:mysqld_db_t:s0 # ls -lZ /home/mysql drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql 

一切都已经到位了。 你应该没有问题重新执行SELinux并让你的服务器上。

 # setenforce 1 # systemctl start mariadb