How to export CSV file with header in mysql

How to export CSV file with header in mysql

Refer to the official document http://dev.mysql.com/doc/refman/5.7/en/select-into.html

mysql> select game,domain,type

-> into outfile 'd:\\game.csv' 
-> fields terminated by ','

-> lines terminated by '\n'

-> from game_lists limit 10;

The following are examples:

mysql> create table test(id int(10) not null auto_increment primary key, name varchar(10) not null, age tinyint(2) not null)engine=innodb default charset=utf8;

mysql> insert into test(`name`,`age`) values ​​('Lee',20),('Li',30),('Wang',22),('Feng',23);

Check the results first

mysql> select * from (select 'name','age' union select name,age from test) b;
+------+-----+
| name | age |
+------+-----+
| name | age |
| Lee | 20 |
| Li | 30 |
| Wang | 22 |
| Feng | 23 |
+------+-----+
5 rows in set (0.00 sec)

Export CSV file

mysql> select * into outfile 'd:\\tmp\\columns.csv' fields terminated by ',' lines terminated by '\n' from (select 'name','age' union select name,age from test) b;
Query OK, 5 rows affected (0.00 sec)

The above method of exporting MySQL CSV files with headers is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to solve the problem of Chinese garbled characters when importing and exporting csv in Mysql
  • How to import csv format data file solution into MySQL
  • How to export MySQL data to csv format
  • PHP exports MySQL data to Excel file (fputcsv)
  • How to solve the problem of unsuccessful import of csv data into mysql using SQLyog
  • How to import csv file into mysql database using php
  • How to export mysql query results to csv
  • Python implements the method of exporting data from MySQL database table to generate csv format file
  • How to parse csv data and import it into mysql
  • Import csv file into mysql using navicat

<<:  Alibaba Cloud Server Ubuntu Configuration Tutorial

>>:  Let’s take a look at JavaScript precompilation (summary)

Recommend

Writing Snake Game with Native JS

This article shares the specific code of writing ...

Quickly solve the problem that the mysql57 service suddenly disappeared

one, G:\MySQL\MySQL Server 5.7\bin> mysqld --i...

Explanation of the execution priority of mySQL keywords

As shown below: from table where condition group ...

Using Nginx to implement grayscale release

Grayscale release refers to a release method that...

Vue Element front-end application development to obtain back-end data

Table of contents Overview 1. Acquisition and pro...

Vue custom components use event modifiers to step on the pit record

Preface Today, when I was using a self-written co...

How to set a dotted border in html

Use CSS styles and HTML tag elements In order to ...

Web Design Tutorial (1): Steps and Overall Layout

<br /> Note: All texts, except those indicat...

Detailed explanation of transaction isolation levels in MySql study notes

background When we talk about transactions, every...

Tutorial on using the frameset tag in HTML

Frameset pages are somewhat different from ordina...

Summary of the use of vue Watch and Computed

Table of contents 01. Listener watch (1) Function...