我在另一台机器复制的mysql目录,到另一台机器,发现数据库无法启动
[root@86c3b0885710 opt]# tail -f /var/log/mariadb/mariadb.log
190627 14:24:51 InnoDB: Using Linux native AIO
190627 14:24:51 InnoDB: Initializing buffer pool, size = 128.0M
190627 14:24:51 InnoDB: Completed initialization of buffer pool
190627 14:24:51 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.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
190627 14:24:51 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
查看下目录
[root@jumpserverdockerallinone mysql]# ll
总用量 45088
-rw-r----- 1 root root 16384 6月 27 14:12 aria_log.00000001
-rw-r----- 1 root root 52 6月 27 14:12 aria_log_control
-rw-r----- 1 root root 35651584 6月 27 14:12 ibdata1
-rw-r----- 1 root root 5242880 6月 27 14:12 ib_logfile0
-rw-r----- 1 root root 5242880 6月 27 14:12 ib_logfile1
drwx------ 2 root root 4096 6月 27 14:12 jumpserver
drwx------ 2 root root 4096 6月 27 14:12 mysql
drwx------ 2 root root 4096 6月 27 14:12 performance_schema
drwx------ 2 root root 6 6月 27 14:12 test
网上查到是因为权即问题
[root@jumpserverdockerallinone opt]# chown -R mysql.mysql /opt/mysql/
[root@jumpserverdockerallinone opt]# ll
总用量 4500
drwx--x--x 4 root root 28 6月 18 14:56 containerd
-rw-r--r-- 1 root root 4606738 6月 27 14:07 jmadb.sql
drwxr-xr-x 3 root root 20 6月 18 10:57 jumpserver
drwxr-xr-x 6 mysql mysql 195 6月 27 14:27 mysql
drwxr-xr-x 5 root root 74 6月 18 14:56 py3
[root@jumpserverdockerallinone opt]# cd mysql/
[root@jumpserverdockerallinone mysql]# ll
总用量 45088
-rw-r----- 1 mysql mysql 16384 6月 27 14:12 aria_log.00000001
-rw-r----- 1 mysql mysql 52 6月 27 14:12 aria_log_control
-rw-r----- 1 mysql mysql 35651584 6月 27 14:28 ibdata1
-rw-r----- 1 mysql mysql 5242880 6月 27 14:28 ib_logfile0
-rw-r----- 1 mysql mysql 5242880 6月 27 14:28 ib_logfile1
drwx------ 2 mysql mysql 4096 6月 27 14:12 jumpserver
drwx------ 2 mysql mysql 4096 6月 27 14:12 mysql
srwxrwxrwx 1 mysql mysql 0 6月 27 14:27 mysql.sock
drwx------ 2 mysql mysql 4096 6月 27 14:12 performance_schema
drwx------ 2 mysql mysql 6 6月 27 14:12 test
再启动下mysql,ok
###############################################
以下部分引用自https://www.linuxidc.com/Linux/2012-11/74612.htm
今天在 Linux 系统上移动 MySQL 的数据库目录
配置如下:
/etc/my.cnf
[mysqld]
datadir=/home/mysql
socket=/var/lib/mysql/mysql.sock
更改完配置文件重启MYSQL的时候出现的以下问题
110222 11:15:07 mysqld_safe Starting mysqld daemon with databases from /home/mysql
110222 11:15:07 [Warning] Can't create test file /home/mysql/localhost.lower-test
110222 11:15:07 [Warning] Can't create test file /home/mysql/localhost.lower-test
/usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
110222 11:15:07 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110222 11:15:07 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.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
110222 11:15:07 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
当初以为只是文件或文件夹权限问题,把所有对应的目录和文件的权限改成读写状态...还是没用...
在网上找了一会儿,找到解决方法了~
解决方法如下:
#在终端中先输入下面这一行
chown -R mysql:mysql /home/data/mysql
#在输入下面的一行就OK了
chcon -R -t mysqld_db_t /home/mysql
#重启下MYSQL试试~
/etc/init.d/mysqld restart