1. 程式人生 > >MySQL伺服器間遷移資料目錄問題

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