欢迎投稿

今日深度:

mysql将数据导入到excel中,mysqlexcel

mysql将数据导入到excel中,mysqlexcel


先创建一张测试的数据表

create table users(

 username varchar(40) not null,

 password varchar(40) not null)charset=utf8;

插入数据

insertinto users values("admin","admin");

insertinto users values("理央silence","王培坤");

使用下面的语句将数据库中的数据写入test.xls文件中

mysql>select username,password from users into outfile "d:\\test.xls";

(注意,这里mysql对该文件的路径要有写入的权限)

(或者使用下面的语句导出到excel中select* into outfile "d:\\test1.xls" from test;)

因为office默认的是gb2312编码,而服务器使用的可能是utf-8编码,那么excel文件可能会出现乱码,如下:


我们可以给某个字段进行重新编码,如下:

mysql>select convert(username using gb2312),convert(password using gb2312) from

 users into outfile "d:\\test.xls";

这是文件中的正常显示:


mysql> select convert(username using gb2312),convert(password using gb2312)from

 users into outfile "d:\\test.xls";

www.htsjk.Com true http://www.htsjk.com/shujukunews/7961.html NewsArticle mysql将数据导入到excel中,mysqlexcel 先创建一张测试的数据表 create table users( username varchar(40) not null, password varchar(40) not null)charset=utf8; 插入数据 insertinto users values(admin,admin); insertinto user...
相关文章
    暂无相关文章
评论暂时关闭