使用select into進行備份
使用select into進行備份與mysqldump很相似,同樣是把數據庫備份到一個指定的文件中。其結果文件只能被建立在mysql服務器上,而不是任何其他主機。select into語句的語法格式如下:
select … into outfile ‘path_and_filename’ ;
示例:
使用select into語句查詢數據庫“mr_mysql”中的“mr_gly”表,把該表備份到“d:gly.txt”目錄下,文件的名稱是“gly.txt”。
mysql> use mr_mysql
database changed
mysql> select * from mr_gly into outfile “d:gly.txt”;
query ok, 5 rows affected (0.00 sec)
下面的這些參數是select into語句的非默認參數。
[fields
[terminated by ‘ ‘ ]???????????? //設置輸出文件以什么作為分界標識
[enclosed by ” ]?????????????? //指定的字符包圍了所有的域
[[optionally] enclosed by ” ]???? //指定只有字符域被包括
[escaped by ”] ]
[lines terminated by ‘ ‘ ]????????? //設置長行的中斷被什么字符代替
下面是應用了select into語句非默認參數的幾個示例。
示例:
在每個域之間,默認的制表符被字符“|”代替。
mysql> use tpsc
database changed
mysql> select * from jtsr into outfile “d:user1.txt” fields terminated by ‘|’ ;
query ok, 5 rows affected (0.00 sec)
示例:
enclosed關鍵字用指定的字符“雙引號”包圍了所有的域。
mysql> select * from jtsr into outfile “d:user2.txt” fields terminated by ‘|’ enclosed by ‘”‘;
query ok, 5 rows affected (0.02 sec)
示例:
optionally關鍵字的使用,導致了只有字符域被雙引號包括。
mysql> select * from jtsr into outfile “d:user3.txt” fields terminated by ‘|’ optionally enclosed by ‘”‘ ;
query ok, 5 rows affected (0.02 sec)
示例:
lines terminated的使用,使每行之間的中斷被字符“ ”代替。
mysql> select * from jtsr into outfile “d:user4.txt” fields terminated by ‘|’ lines terminated by ‘ ‘ ;
query ok, 5 rows affected (0.02 sec)
示例:
綜合使用這些參數。
mysql> select * from jtsr into outfile “d:user5.txt” fields terminated by ‘|’ optionally enclosed
by ‘”‘ lines terminated by ‘ ‘ ;
query ok, 5 rows affected (0.02 sec)
示例:
使用select語句中的條件進行備份。
mysql> select * from jtsr where id>3 into outfile “d:user6.txt” fields terminated by ‘|’ optionall
y enclosed by ‘”‘ lines terminated by ‘ ‘ ;
query ok, 2 rows affected (0.01 sec)
注意:在使用select into語句時,為備份的文件命名時切忌不要重寫已存在的文件;在編寫文件輸出的位置時不要忘記使用換碼符“”。
?以上就是mysql教程:使用SELECT INTO進行備份的內容,更多相關文章請關注PHP中文網(www.php.cn)!