mysql匯出的資料 mysql匯出匯入資料

2021-10-17 21:56:09 字數 1367 閱讀 2127

使用sql語句匯出資料:

匯出時如果不寫絕對路徑,會提示the mysql server is running with the --secure-file-priv option so it cannot execute this statement。

使用 show variables like "%secure%" 檢視secure_file_priv 設定的路徑,匯出時必須是這個路徑才能匯出,預設null的話是禁止匯出的。

匯出命令:select id,分數 from score into outfile "/var/lib/mysql-files/score.txt";  (id,分數是列名,score是表名)

加上逗號分隔和引號:select id,分數 from score into outfile "/var/lib/mysql-files/score1.txt" fields terminated by "," enclosed by '"';

使用mysqldump匯出檔案:mysqldump -t ./ schooldb score --fields-terminated-by ',' --fields-optionally-enclosed-by '"';

mysql匯出:

mysql -uroot -p*** --vertical --execute=' select id from score ;' schooldb > /var/lib/mysql-files/score.txt

[root@hkdlvm00 mysql-files]# cat score.txt

*************************** 1. row ***************************

id: 1

*************************** 2. row ***************************

id: 2

*************************** 3. row ***************************

id: 3

匯出時,去掉*****注釋:mysql -uroot -p*** --execute=' select id from score ;' schooldb > /var/lib/mysql-files/score.txt

id匯入資料:load data infile '/var/lib/mysql-files/score.txt' into table score  ignore 1 lines (班級);

load data infile '/var/lib/mysql-files/score.txt' into table score  ignore 1 lines (班級) set 分數=77;    (設定分數欄的所有預設值為77)

mysql本地匯入匯出 MySQL資料匯出與匯入

工具 mysql mysqldump 應用舉例 匯出匯出全庫備份到本地的目錄 mysqldump u user p passwd h127.0.0.1 p3306 routines default character set utf8 lock all tables add drop databas...

mysql 匯出資料

方法一 select.into outfile mysql select from mytbl into outfile tmp mytbl.txt 檢視mytbl.txt中內容如下 mysql system cat tmp mytbl.txt1 name1 2 name2 3 n 匯出的檔案中資料...

MySQL資料匯出

方法一 select.into outfile mysql select from mytbl into outfile tmp mytbl.txt query ok,3 rows affected 0.00 sec 檢視mytbl.txt中內容如下 mysql system cat tmp myt...