mysql數據庫表結構導出到Excel中


數據庫導出表結構sql語句:

select column_name as 字段類型,
     column_type as 數據類型,
     data_type as 字段類型,
     character_maximum_length as 長度,
     is_nullable as 是否為空,
     column_default as 默認值,
     column_comment as 備注
from
     information_schema.columns
where
     table_schema = '數據庫名稱' and table_name = '表名稱'

 

查詢出表結構,可以點擊導出結果將查詢的結果導出

也可以:

select column_name as 字段類型,
     column_type as 數據類型,
     data_type as 字段類型,
     character_maximum_length as 長度,
     is_nullable as 是否為空,
     column_default as 默認值,
     column_comment as 備注
from
     information_schema.columns
where
     table_schema = '數據庫名稱' and table_name = '表名稱'
     into outfile 'C:/Users/Admintor/Desktop/abc.xls'   -- 導出到桌面的Excel表格

 

執行sql語句

如果執行這個sql語句報錯時:--secure-file-priv
mysql限制了導入與導出的目錄權限 需要修改mysql.ini配置文件

進入mysql執行show variables like '%secure%'; 發現secure_file_priv路徑為NULL
修改mysql.ini中,添加一句
secure-file-priv = C:/Users/權煥旭/Desktop/

重啟MySQL,然后再次查看當前的secure-file-priv
show variables like '%secure%';

然后執行sql語句 可以正常導出

還可以:

新建一個excel表格,將查詢的數據全選后右擊選擇復制為-制表符分隔值(欄位名和數據),復制到Excel表格中


免責聲明!

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



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