MySQL服务器间迁移数据目录问题


1. 拷贝数据目录 /var/lib/mysql到新服务器
1)scp拷贝数据目录,文件属性会改变,修改: /var/lib # chown mysql:mysql -R mysql

2)压缩后scp拷贝,会保留原文件属性权限

3)rsync拷贝数据目录,会保留原文件属性权限


2. 在新服务器使用拷贝的数据目录启动mysql
错误日志:
--------
160315 14:46:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160315 14:46:39 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
160315 14:46:39 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
160315 14:46:39 InnoDB: The InnoDB memory heap is disabled
160315 14:46:39 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160315 14:46:39 InnoDB: Compressed tables use zlib 1.2.3
160315 14:46:39 InnoDB: Using Linux native AIO
160315 14:46:39 InnoDB: Initializing buffer pool, size = 128.0M
160315 14:46:39 InnoDB: Completed initialization of buffer pool
160315 14:46:39  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.
160315 14:46:39 mysqld_safe mysqld from pid file /var/lib/mysql/srv200.pid ended
--------
1) 尝试删除数据目录下日志文件:
mysql # rm ib_logfile* -f
2) 确认数据目录chown,chmod权限没问题;
3) selinux问题检查
# vim /etc/selinux/config # 尝试修改
SELINUX=enforcing to SELINUX=permissive
/var/lib # ls -Z mysql_bak_0 # 原数据目录
drwx--x--x. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 mysql
drwx------. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 performance_schema
-rw-r--r--. root  root  unconfined_u:object_r:mysqld_db_t:s0 RPM_UPGRADE_HISTORY
-rw-r--r--. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x. mysql mysql unconfined_u:object_r:mysqld_db_t:s0 test
/var/lib # ls -Z mysql       # 拷贝的数据目录
-rw-rw----. mysql mysql unconfined_u:object_r:var_lib_t:s0 ibdata1
drwx--x--x. mysql mysql unconfined_u:object_r:var_lib_t:s0 mysql
drwx------. mysql mysql unconfined_u:object_r:var_lib_t:s0 performance_schema
-rw-r--r--. root  root  unconfined_u:object_r:var_lib_t:s0 RPM_UPGRADE_HISTORY
-rw-r--r--. mysql mysql unconfined_u:object_r:var_lib_t:s0 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x. mysql mysql unconfined_u:object_r:var_lib_t:s0 test

/var/lib # chcon -R -t mysqld_db_t mysql # 修改

再次启动mysql,成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章