- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我在 MySQL
中有下表
create table test_tbl
(
col1 varchar(100),
col2 varchar(100),
amount int,
created datetime
)
数据插入
Insert into test_tbl values('unu', 'doi', 10, '05/01/2015');
Insert into test_tbl values('patru', trei', 400, '04/01/2015');
我需要按以下格式导出该表中的所有数据。该文件应该是txt文件。
"col1"="unu","col2"="doi","amount"="10","created"="05/01/2015"
"col1"="patru","col2"="trei","amount"="400","created"="04/01/2015"
所以逻辑是:每个列名称及其值以逗号分隔。
在MySQL
中可能得到这样的结果吗?
最佳答案
用于导出表的数据-
SELECT CONCAT('"col1"="',col1,'","col2"="',col2,'","amount"="',amount,'","created"="',DATE_FORMAT(created,'%d/%m/%Y'),'"') t FROM test_tbl INTO OUTFILE '/tmp/test.txt' CHARACTER SET latin1 FIELDS ENCLOSED BY '' LINES TERMINATED BY '\r\n';
用于从 csv 导入表格
mysql> CREATE TABLE `test_tbl` (
-> `col1` varchar(100) DEFAULT NULL,
-> `col2` varchar(100) DEFAULT NULL,
-> `amount` int DEFAULT NULL,
-> `created` datetime DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1
-> ;
Query OK, 0 rows affected (0.44 sec)
mysql> load data local infile 'test.txt' into table test_tbl fields terminated by ',' ENCLOSED BY '"' lines terminated by '\r\n' (@col1, @col2,@col3,@col4)
-> set col1 = substr(@col1,8), col2 = substr(@col2,8), amount = substr(@col3,10), created = str_to_date(substr(@col4,11), '%d/%m/%Y');
Query OK, 2 rows affected (0.09 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> select * from test_tbl;
+-------+------+--------+---------------------+
| col1 | col2 | amount | created |
+-------+------+--------+---------------------+
| unu | doi | 10 | 2015-01-05 00:00:00 |
| patru | trei | 400 | 2015-01-04 00:00:00 |
+-------+------+--------+---------------------+
2 rows in set (0.00 sec)
关于MySQL导出表到文本文件字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30234909/
是的,我有这个对象,属性代表数据库表列作为属性,但它们都是大写的...如何将对象的所有属性更改为小写,而不将对象转换为将属性从大写转换为小写后的数组?..我想我可以用array_change_key_
是的,我有这个对象,属性代表db表的列作为属性,但是都是大写的...如何把对象的所有属性都变成小写,而不把对象转换成将属性从大写转换为小写后的数组?..我以为我可以用array_change_key_
我目前有一个论坛的 MySQL 帖子表。这包括父帖子和子帖子。如果它是父帖子,则它有一个主题。如果它是子帖子,则包含 parent_id。 例如: TABLE posts +----+--------
我正在添加一个临时表,其中包含第二个查询将使用的文件名列表。我知道文件名可以用于sql注入(inject),所以我想使用准备好的语句。 我的工作查询的简化版本如下所示(例如可能有 50 个文件名):
MySQL中查询所有数据库名和表名 查询所有数据库 ? 1
有人能给我指出正确的方向/网站吗 在 PHP 中有没有一种方法可以通过比较来自 FORM 的字段名称和来自数据库的 column_name 来动态更新特定的表。 例如 INPUT name="emai
获取表名及注释: ? 1
我正在使用 Pyshark 来解析 Wireshark 嗅探器日志,并且在使用“get_field_value”函数检索字段值时,我使用导出的 Json 格式文件(基于 pcapny 文件)来查找字段
我已经从以下 xsd 文件创建了 java bean 人.xsd
我用 MySQL 查询浏览器生成了一个 XML。我正在尝试应用 XSLT 将结果输出到 Word 表中。每条记录一张表。 这是我的 XML 示例 Critique
我有一个 select2 下拉列表,它配置为与远程数据一起使用。但是,我的远程数据源提供的搜索结果格式似乎与 select2 不兼容。远程数据例如是这样的: ... items: [ { value:
最好的 此时我在 python 2.7 中使用 Boto3,我想要的是:我的特定 DynamoDB 表的列标题。 此时,我正在处理一个非常大的 dynamoDB 表,有 80 列和 + 1.00O.0
错误信息 我刚刚试用了 Django-Rest-Framework 3.0 quickstart tutorial (伟大的介绍顺便说一句)并在我自己的系统/表上实现它时遇到了这个错误。 Improp
我正在尝试使用 haystack-whoosh 创建多个查询,我的最后一个问题是通过放置双反斜杠解决的,但现在出现了一个新错误。我在命令提示符中收到以下错误: C:\Users\varun\De
在尝试更新文档时,我在字段 timesToDisplay 中收到上述错误。 MongoDB 版本 2.6.7。 整个模型: msg = { 'name': '',
我是一名优秀的程序员,十分优秀!