1. 程式人生 > >CentOS7安裝mysql並匯入csv檔案問題彙總

CentOS7安裝mysql並匯入csv檔案問題彙總

 

       專案測試mysql資料匯入功能,所以自己搭建資料庫伺服器,測試產品功能。在安裝匯入的過程中遇到了大量問題,最終一一解決,在自己記錄下自己解決問題的過程,可供參考。

一、mysql安裝之後啟動失敗,通過檢視/var/log/mysqld.log日誌檔案報如下錯誤:

2018-10-17T04:29:31.727009Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.12) starting as process 1654
2018-10-17T04:29:31.738339Z 1 [ERROR] [MY-012592] [InnoDB] InnoDB: Operating system error number 13 in a file operation.
2018-10-17T04:29:31.738373Z 1 [ERROR] [MY-012595] [InnoDB] InnoDB: The error means mysqld does not have the access rights to the directory.
2018-10-17T04:29:31.738386Z 1 [ERROR] [MY-012270] [InnoDB] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2018-10-17T04:29:31.738406Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2018-10-17T04:29:31.738524Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2018-10-17T04:29:31.738549Z 0 [ERROR] [MY-010119] [Server] Aborting

檢視資料庫data目錄許可權:

/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

需要修改目錄許可權解決

chcon -R -t mysqld_db_t mysql

問題原因是selinux的許可權控制問題,更改下就可以了。

二、匯入csv檔案一直報錯:

匯入資料的時候,報如上錯誤!發現從本地匯入檔案的引數沒有開啟;

mysql> SHOW VARIABLES LIKE '%local%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

開啟該引數,因為是全域性引數,所以需要加上global;

SET GLOBAL local_infile=1

再次匯入資料,匯入成功!

load data local infile '/opt/data-set/1_train_19_Run_or_walk_information.csv' into table `test`.`19_normal` character set utf8 fields terminated by ',' enclosed by '"' lines terminated by '\r\n';

另外注意LINES TERMINATED BY '\r\n',在linux上需要用'\r\n',windows上使用'\n'