MYSQL入坑第一彈--------ERROR 1148 (42000)&&&ERROR 1290 (HY000)


一、運行Load data local infile命令時:
mysql> LOAD DATA LOCAL INFILE '/path/file' INTO TABLE tablename;1
出現:
 
ERROR 1148 (42000): The used command is not allowed with this MySQL version
這是因為:
服務器端,local_infile默認開啟;客戶端,local_infile默認關閉,因此用的時候需要打開。

  On the server side:
  The local_infile system variable controls server-side LOCAL capability. Depending on the local_infile setting, the server refuses or permits local data loading by clients that have LOCAL enabled on the client side. By default, local_infile is enabled.
  On the client side:
  For the mysql client, local data loading is disabled by default. To disable or enable it explicitly, use the –local-infile=0 or –local-infile[=1] option.
  該怎么辦呢?
  可以:
 
mysql> show global varaiables like 'local_infile';1
出現:
 
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | OFF    |
+---------------+-------+
1 row in set (0.00 sec)123456
可以這么做:
 
mysql> set global local_infile = 'ON';1
local_infile其實是bool變量,但這里用ON。
然后可以看到:
 
mysql> show global variables like 'local_infile';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile  | ON    |
+---------------+-------+
1 row in set (0.00 sec)1234567
然后再試試Load data,本人仍舊出錯還是:
 
ERROR 1148 (42000): The used command is not allowed with this MySQL version1
因而退出mysql,執行quit或exit,然后用如下命令登錄mysql:
 
$ mysql --local-infile=1 -u root -p1
然后就可以順利Load data infile了。
https://dev.mysql.com/doc/refman/5.7/en/load-data-local.html
二、在做mysql 大批量導出數據的時候,所遇到的問題如下:
 
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
 
mysql 默認對導出的目錄有權限限制,也就是說使用命令行進行導出的時候,需要指定目錄進行操作;
 
解決方法:
   1. 查詢mysql 的secure_file_priv 值配置的是什么,使用命令行: show global variables like '%secure%'; 
     (我這里的配置是 secure_file_priv = /var/lib/mysql-files/)
 
   2. 使用 into outfile 開始導出:(因為secure_file_priv配置的關系,所以必須導出到  /var/lib/mysql-files/目錄下)
      select * from table_name where a = 'test'
into outfile '/var/lib/mysql-files/test.txt'  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
 
  3.所用的幾個關鍵字:
FIELDS TERMINATED BY  ','  OPTIONALLY ENCLOSED BY  ' " '  LINES TERMINATED BY '\n';
(因為導出的數據會出現一些亂碼或者特殊字符,所以使用以上關鍵字進行轉義)
參考:https://blog.csdn.net/slvher/article/details/8768468


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM