mysql導出和導入xml文件

1,輸出數據庫版本變量爲xml格式 
Shell> mysql -X -uroot -proot -e "use test; show variables like '%version%';" 
參數X表示生成xml格式的輸出 , 參數e表示執行後面的命令 
protocol_version 
10 
version 
5.0.22-community-nt-log 
version_comment 
MySQL Community Edition (GPL) 
version_compile_machine 
ia32
version_compile_os 
Win32 
2,導出表數據到xml文件 
Shell> mysql -X -uroot -proot -e "use test; select * from test;" > ./a.xml 
Shell> more a.xml 
111 
10 

110 
3,換一種方式導出表結構和內容,其中第一個db_name是數據庫名,第二個test是表名 
Shell> mysqldump --xml -uroot -proot db_name test 
<options name="test" engine="InnoDB" version="10" row_format="Compact" rows="4" avg_row_length="4096" data_length="16384" max_data_length="0" index_length="0" data_free="0" create_time=""
="2008-09-04 02:45:12" Collation="utf8_general_ci" Create_options="" Comment="InnoDB free: 11264 kB" /> 
111 
10 

110 
4,導入xml文件的內容到數據庫表,這裏主要用到了load_file()函數 
mysql> create table xmlt( 
-> id int , 
-> doc blob 
-> ); 

mysql> insert into xmlt values(1,load_file('/home/a.xml') ); 

mysql> select * from xmlt; 
+------+-------------------------------------- 
---------------------------------------------- 
| id | doc 
+------+-------------------------------------- 
---------------------------------------------- 
| 1 | 
111 
10 

110 
發佈了18 篇原創文章 · 獲贊 3 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章