如何在select into outfile 的文件中显示column name

正常情况先select into outfile 生产的文件是不包含column name,比如如下sql
(root@localhost) [test]>SELECT EVENT_NAME ,COUNT_STAR from events_stages_summary_global_by_event_name; +---------------------------------------------------------------------------------------+------------+ | EVENT_NAME                                                                            | COUNT_STAR | +---------------------------------------------------------------------------------------+------------+ | stage/sql/After create                                                                |          0 | | stage/sql/allocating local table                                                      |          0 | | stage/sql/preparing for alter table                                                   |          0 | | stage/sql/altering table                                                              |          0 | | stage/sql/committing alter table to storage engine                                    |          0 | | stage/sql/Changing master                                                             |          0 | | stage/sql/Checking master version                                                     |          0 | | stage/sql/checking permissions                                                        |          0 | | stage/sql/checking privileges on cached query                                         |          0 | | stage/sql/checking query cache for query                                              |          0 | | stage/sql/cleaning up                                                                 |          0 | | stage/sql/closing tables                                                              |          0 | | stage/sql/Connecting to master                                                        |          0 | | stage/sql/converting HEAP to MyISAM                                                   |          0 | | stage/sql/Copying to group table                                                      |          0 | | stage/sql/Copying to tmp table                                                        |          0 | | stage/sql/copy to tmp table                                                           |          0 | | stage/sql/Creating delayed handler                                                    |          0 | | stage/sql/waiting for delay_list                                                      |          0 | | stage/sql/waiting for handler insert                                                  |          0 | | stage/sql/waiting for handler lock                                                    |          0 | | stage/sql/waiting for handler open                                                    |          0 | | stage/sql/Waiting for INSERT                                                          |          0 | | stage/sql/Waiting for master to send event                                            |          0 | | stage/sql/Waiting for master update                                                   |          0 | | stage/sql/Waiting for slave mutex on exit                                             |          0 | | stage/sql/Waiting for slave thread to start                                           |          0 | | stage/sql/Waiting for table flush                                                     |          0 | | stage/sql/Waiting for query cache lock                                                |          0 | | stage/sql/Waiting for the next event in relay log                                     |          0 | | stage/sql/Waiting for the slave SQL thread to advance position                        |          0 | | stage/sql/Waiting to finalize termination                                             |          0 | | stage/sql/Waiting to get readlock                                                     |          0 | | stage/mysys/Waiting for table level lock                                              |          0 | | stage/sql/Waiting on empty queue                                                      |          0 | | stage/sql/Waiting for next activation                                                 |          0 | | stage/sql/Waiting for the scheduler to stop                                           |          0 | | stage/sql/Waiting for global read lock                                                |          0 | | stage/sql/Waiting for schema metadata lock                                            |          0 | | stage/sql/Waiting for table metadata lock                                             |          0 | | stage/sql/Waiting for stored function metadata lock                                   |          0 | | stage/sql/Waiting for stored procedure metadata lock                                  |          0 | | stage/sql/Waiting for trigger metadata lock                                           |          0 | | stage/sql/Waiting for event metadata lock                                             |          0 | | stage/sql/Waiting for commit lock                                                     |          0 | +---------------------------------------------------------------------------------------+------------+ 108 rows in set (0.00 sec)


使用select 列出所有的字段,比如select "Col1","Col2".... union all

(root@localhost) [test]>select "EVENT_NAME","COUNT_STAR"      -> union all      -> SELECT EVENT_NAME ,COUNT_STAR from events_stages_summary_global_by_event_name; +---------------------------------------------------------------------------------------+------------+ | EVENT_NAME                                                                            | COUNT_STAR | +---------------------------------------------------------------------------------------+------------+ | EVENT_NAME                                                                            | COUNT_STAR | | stage/sql/After create                                                                | 0          | | stage/sql/allocating local table                                                      | 0          | | stage/sql/preparing for alter table                                                   | 0          | | stage/sql/altering table                                                              | 0          | | stage/sql/committing alter table to storage engine                                    | 0          | | stage/sql/Changing master                                                             | 0          | | stage/sql/Checking master version                                                     | 0          | | stage/sql/checking permissions                                                        | 0          | | stage/sql/checking privileges on cached query                                         | 0          | | stage/sql/checking query cache for query                                              | 0          | | stage/sql/cleaning up                                                                 | 0          | | stage/sql/closing tables                                                              | 0          | | stage/sql/Connecting to master                                                        | 0          | | stage/sql/Waiting for table metadata lock                                             | 0          | | stage/sql/Waiting for stored function metadata lock                                   | 0          | | stage/sql/Waiting for stored procedure metadata lock                                  | 0          | | stage/sql/Waiting for trigger metadata lock                                           | 0          | | stage/sql/Waiting for event metadata lock                                             | 0          | | stage/sql/Waiting for commit lock                                                     | 0          | +---------------------------------------------------------------------------------------+------------+ 109 rows in set (0.00 sec)

或者直接使用mysql -e > a.log 的方式来实现

mysql -u gf -p test -e "SELECT EVENT_NAME ,COUNT_STAR from events_stages_summary_global_by_event_name" > /home/mysql/event2.dat


你可能感兴趣的:(column,select,文件)