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,成功。

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