91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL數據庫怎么用命令行導出帶表頭和不帶表頭的csv文件

發布時間:2021-08-06 19:15:11 來源:億速云 閱讀:1366 作者:chen 欄目:MySQL數據庫

本篇內容介紹了“MySQL數據庫怎么用命令行導出帶表頭和不帶表頭的csv文件”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

實驗如下:
建表:
mysql> CREATE TABLE `test` (
    ->   `id` varchar(64) NOT NULL,
    ->   `ecode` varchar(10) DEFAULT NULL,
    ->   `type` varchar(12) DEFAULT NULL,
    ->   `timeid` varchar(12) DEFAULT NULL,
    ->   `start_time` date DEFAULT NULL,
    ->   `end_time` varchar(12) DEFAULT NULL,
    ->   PRIMARY KEY (`id`),
    ->   KEY `start` (`start_time`),
    ->   KEY `end` (`end_time`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.35 sec)


mysql>
mysql>
插入數據:
mysql> insert into test select * from date_rule;
Query OK, 1412 rows affected (0.49 sec)
Records: 1412  Duplicates: 0  Warnings: 0




不帶表頭:
mysql> select * from test into outfile 'd:\test.csv' fields terminated by ','enclosed by '"'lines terminated by '\r\n';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement


導出報錯,原因是5.7版本對mysqld 的導入導出做限制,解決辦法:
在my.ini中加上
[mysqld]
secure_file_priv=''
重啟數據庫使配置生效


PS C:\WINDOWS\system32> net stop mysql
MySQL 服務正在停止.
MySQL 服務已成功停止。


PS C:\WINDOWS\system32> net start mysql
MySQL 服務正在啟動 ..
MySQL 服務已經啟動成功。


再次運行命令成功:
mysql> select * from test into outfile "d:/test.csv" fields terminated by ','enclosed by '"'lines terminated by '\r\n';
Query OK, 1412 rows affected (0.00 sec)


用Notepad++打開文件發現沒表頭:
"00000c-month-20161","00000c","month","20161","2015-12-29","2016-01-28"
"00000c-month-201610","00000c","month","201610","2016-09-29","2016-10-28"
"00000c-month-201611","00000c","month","201611","2016-10-29","2016-11-28"
"00000c-month-201612","00000c","month","201612","2016-11-29","2016-12-28"
"00000c-month-20162","00000c","month","20162","2016-01-29","2016-02-28"
"00000c-month-20163","00000c","month","20163","2016-02-29","2016-03-28"
"00000c-month-20164","00000c","month","20164","2016-03-29","2016-04-28"
"00000c-month-20165","00000c","month","20165","2016-04-29","2016-05-28"
"00000c-month-20166","00000c","month","20166","2016-05-29","2016-06-28"
"00000c-month-20167","00000c","month","20167","2016-06-29","2016-07-28"
"00000c-month-20168","00000c","month","20168","2016-07-29","2016-08-28"
"00000c-month-20169","00000c","month","20169","2016-08-29","2016-09-28"
"00000c-month-20171","00000c","month","20171","2016-12-29","2017-01-28"
"00000c-month-201710","00000c","month","201710","2017-09-29","2017-10-28"
"00000c-month-201711","00000c","month","201711","2017-10-29","2017-11-28"
.........................................................................
.........................................................................






查看表結構:
mysql> desc test;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id         | varchar(64) | NO   | PRI | NULL    |       |
| ecode      | varchar(10) | YES  |     | NULL    |       |
| type       | varchar(12) | YES  |     | NULL    |       |
| timeid     | varchar(12) | YES  |     | NULL    |       |
| start_time | date        | YES  | MUL | NULL    |       |
| end_time   | varchar(12) | YES  | MUL | NULL    |       |
+------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)


帶表頭導出csv:
mysql> select * from (select 'id','ecode','type','timeid','start_time','end_time' union all select id,ecode,type,timeid,start_time,end_time from test) b  into outfile "d:/test.csv" fields terminated by ','enclosed by '"'lines terminated by '\r\n';
Query OK, 1413 rows affected (0.01 sec)

用Notepad++打開文件發現帶表頭:
"id","ecode","type","timeid","start_time","end_time"
"00000c-month-20161","00000c","month","20161","2015-12-29","2016-01-28"
"00000c-month-201610","00000c","month","201610","2016-09-29","2016-10-28"
"00000c-month-201611","00000c","month","201611","2016-10-29","2016-11-28"
"00000c-month-201612","00000c","month","201612","2016-11-29","2016-12-28"
"00000c-month-20162","00000c","month","20162","2016-01-29","2016-02-28"
"00000c-month-20163","00000c","month","20163","2016-02-29","2016-03-28"
"00000c-month-20164","00000c","month","20164","2016-03-29","2016-04-28"

“MySQL數據庫怎么用命令行導出帶表頭和不帶表頭的csv文件”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

商丘市| 内黄县| 黄陵县| 巧家县| 八宿县| 邻水| 阳山县| 湛江市| 玛曲县| 阿勒泰市| 钟祥市| 博野县| 定结县| 保德县| 阳西县| 巴彦淖尔市| 油尖旺区| 赤壁市| 富蕴县| 海阳市| 陇西县| 仙游县| 谢通门县| 阿巴嘎旗| 长垣县| 上犹县| 闵行区| 兴宁市| 毕节市| 通山县| 上高县| 霍山县| 二连浩特市| 商水县| 徐水县| 舟曲县| 龙岩市| 南和县| 霍邱县| 龙陵县| 乾安县|