mysql匯出的幾種辦法

2021-09-01 14:36:17 字數 2382 閱讀 7832

[size=large]一、使用mysqldump匯出[/size]

mysqldump -uusername -ppwd -hhostname -pport database secure_flow_warning > /home/user/a.txt;

mysqldump -u使用者名稱 -p密碼 資料庫名 表名 --where="篩選條件" > 匯出檔案路徑

例子:從test資料庫的test_data表中匯出id大於100的資料到 /tmp/test.sql 這個檔案中

mysqldump -uroot -p123456 test test_data --where=" id > 100" > /tmp/test.sql

[size=large]二、mysql匯出select結果到檔案[/size]

2013-07-02今天匯出指定列資料,把之前的事情忘得一乾二淨。

mysql -hhostname -uuser -pport -ppassword databasename -e "select id,name from idc_info" > ./aaaa.txt

mysql -hxx -uxx -pxx -e "query statement" db > file

例如:

[color=red]mysql -uusername -ppwd -hhostname -pport database -e "select * from table1" > a.t

#在into outfile "/home/user/a.txt"沒有許可權的情況下,還可以用》匯出資料。[/color]

mysql -h127.0.0.1 -uroot -p000000 -e "select * from table" test > 1.txt

host ip user password query statement database filename

這樣會輸出列名資訊,如果不想輸出列名資訊:

mysql -h127.0.0.1 -uroot -p000000 -n -e "select * from table" test > 1.txt

host ip user password query statement database filename

或mysql -h*** -uxx -pxx

select * from table into outfile '***.txt';

例如:mysql -h127.0.0.1 -uroot -p000000

select * from a into outfile '1.txt';

兩種方法效果一樣的

注:-e 引數應該是export的縮寫。

第二種方式的mysql文件:

select [select options go here] into filename

export_options

from table_references [additional select options go here]

例如:

mysql -h127.0.0.1 -uroot -p000000

select * from table into outfile "1.txt" fields terminated by '\t' lines terminated by '\r\n'

第一種方法和第二種方法的結合:使用 mysql -e執行匯出到檔案的sql語句

mysql -hxx -uxx -pxx -e "query statement" db

例如:

mysql -h127.0.0.1 -uroot -p000000 -e "select * from table into outfile '1.txt' fields terminated by ',' lines terminated by '\r\n'" test

如果不想輸出列名資訊:

mysql -h127.0.0.1 -uroot -p000000 -n -e "select * from table into outfile '1.txt' fields terminated by ',' lines terminated by '\r\n'" test

預設情況下, mysql -e匯出的檔案,列是用"\t"分隔,行是用"\r\n"分隔(dos),行是用"\n"分隔

(unix 追加一種方式:

select col002,col005,col004,col008 into outfile 'e:/mysql/i0812.txt' fields terminated by '|' lines terminated by '\r\n' from table where col003 in (select col001 from qdbm) order by col005;

mysql 匯出匯入的幾種方式

一.1.load data load data infile 匯入的路徑檔案 into table 表名fields terminated by enclosed by escaped by character set utf8 terminated by r n 2 select into out...

Mysql查詢結果匯出為Excel的幾種方法

url 方法一 查詢語句直接輸出 語法格式 example select into outfile data var 3307 catid.xls from help cat where 1 order by cat id desc limit 0,20 select into outfile 匯出...

求逆元的幾種辦法

補了一道cf題,順便看到有人求逆元的方法叼叼的,怪不得人家過題這麼快啊 來總結一發 求a關於n的逆元,即要解同餘方程ax 1 modn 的解x.ax 1 modn ax ny 1 僅當a與n互質時,存在 a 的逆元,利用擴充套件歐幾里得求解。這裡n不一定是素數 ll extend euclid ll...