数据库导出表结构到Excel
程序员文章站
2024-03-21 08:37:46
...
代码如下:
SELECT '字段名称','数据类型','主键','备注'
UNION
SELECT
COLUMN_NAME as 字段名称,
COLUMN_TYPE as 数据类型,
if(COLUMN_KEY='PRI','Y','N') as 主键,
COLUMN_COMMENT as 备注
FROM
INFORMATION_SCHEMA. COLUMNS
WHERE
table_schema = 'mydata'
AND
table_name = 'account'
INTO OUTFILE 'C:/Users/Administrator/Desktop/account.xls'
CHARACTER SET gbk # 中文防止乱码
可能出现的问题:
- The MySQL server is running with the --secure-file-priv option
SHOW VARIABLES LIKE "secure_file_priv"; # 输出到对应目录
- 中文乱码,需要加上
CHARACTER SET gbk # 中文防止乱码