MySQL的CSV引擎应用实例解析

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
如果您想把EXCEL的数据或者CSV格式的数据导入到MySQL中,MySQL的CSV引擎再适合不过了。
MySQL的CSV引擎在5.0后开始提供,不过不支持WINDOWS,到了5.1才支持。
今天我测试的版本号是5.0.45
一、注意几点:
1、没有索引,跟MySQL5的数据字典库一样。
2、可以直接用任何文本编辑器来编辑数据文件。
3、非英文编码问题。
我的字符终端和表都是UTF-8的,所以要把上传的CSV文件保存为UTF-8的编码。
4、编码转化工具,我这边在WINDOWS下用EDITPLUS来转化,在LINUX下可以用ICONV命令行工具来转化编码。
二、示例数据文件。
"1","Designed for 99.999% Availability","MySQL Cluster provides a fault tolerant architecture that ensures your organization's mission critical applications achieve 99.999% availability. This means less than 5 minutes downtime per year, including scheduled maintenance time. MySQL Cluster implements automatic node recoverability to ensure an application automatically fails over to another database node that contains a consistent data set, if one or more database nodes fail. Should all nodes fail due to hardware faults for example, MySQL Cluster ensures an entire system can be safely recovered in a consistent state by using a combination of checkpoints and log execution. Furthermore, MySQL Cluster ensures systems are available and consistent across geographies by enabling entire clusters to be replicated across regions."
"2","High Performance Only a Main Memory Database Can Deliver","MySQL Cluster provides the response time and throughput to meet the most demanding high volume enterprise applications. MySQL Cluster achieves its performance advantage by being a main memory clustered database solution, which keeps all data in memory and limits IO bottlenecks by asynchronously writing transaction logs to disk. MySQL Cluster also enables servers to share processing within a cluster, taking full advantage of all hardware. Typical response times for MySQL Cluster are in the range of a few milliseconds and MySQL Cluster has been proven to handle tens of thousands of distributed transactions per second that are also replicated across database nodes."
"3","Extremely Fast Automatic Failover","MySQL delivers extremely fast failover time with sub-second response so your applications can recover quickly in the event of application, network or hardware failure. MySQL Cluster uses synchronous replication to propagate transaction information to all the appropriate database nodes so applications can automatically fail over to another node extremely quickly. This eliminates the time consuming operation of recreating and replaying log files required by 'Shared-Disk' architectures to fail over successfully. Plus, MySQL Cluster database nodes are able to automatically restart, recover, and dynamically reconfigure themselves in case of failures without having to program advanced features into the application."
"4","Flexible Distributed Architecture with No Single Point of Failure","The parallel server architecture combines database nodes, management server nodes, and application nodes that can be distributed across computers and geographies to ensure there is no single point of failure. Any node can be stopped or started without stopping the applications that use the database. And MySQL Cluster is highly configurable so you can implement the appropriate level of performance, scalability and fault tolerance to match your application requirements."
"5","Significantly Reduce Costly Downtime","MySQL Cluster not only lowers up-front license costs with affordable commercial licensing under a dual licensing mechanism, but it also significantly reduces system downtime - the number one contributor to the Total Cost of Ownership (TCO) of database software. Furthermore, a highly portable standards-based environment allows you to cost-effectively distribute your applications using commodity hardware and open source software infrastructure."
"6","Lower Maintenance Costs","MySQL Cluster is designed to be largely self-governing so very few system parameters actually need fine-tuning, further reducing the risk of costly errors. As a result, there are typically fewer conflicts with other software and hardware, and less need for manual intervention. This also means that MySQL Cluster will have a much lower maintenance costs, with less fine tuning required by Database Administrators."
"7","Easy-to-use Administration","MySQL Cluster includes easy to use and powerful tools for administering your clustered environment. Command line tools enable you to monitor database nodes, control access to applications, and create and restore backups."
"8","Services and Support","MySQL provides extensive consulting, training and technical support services to ensure the success of your next mission-critical database application project. MySQL has a proven track record gained through millions of successful customer deployments that can lower your risk and maximize return on investment."
"9","MySQL CLUSTER","以上是集群的特性概括"
"10","月亮他爸","我博客地址:[url]http://yueliangdao0608.cublog.cn[/url]"
"11","最要注意的一点","最后的一行必须有个空格!如果是中文,好奇怪!"


三、直接COPY数据文件到MySQL数据库目录下。
1、用EDITPLUS转码,然后进入MySQL命令行。
mysql> \C gbk 
Charset changed
mysql> flush tables;
Query OK, 0 rows affected (0.00 sec)
mysql> select sql_calc_found_rows * from ytt order by id desc limit 2\G
*************************** 1. row ***************************
     id: 11
  title: 最要注意的一点
summary: 最后的一行必须有个空格!如果是中文,好奇怪!"
*************************** 2. row ***************************
     id: 10
  title: 月亮他爸
summary: 我博客地址:[url]http://yueliangdao0608.cublog.cn[/url]"
2 rows in set (0.00 sec)

mysql> select found_rows();
+--------------+
| found_rows() |
+--------------+
|           11 | 
+--------------+
1 row in set (0.00 sec)
2、用ICONV转码
现在可以直接用EXCEL来编辑数据文件,不过可惜的是EXCEL的编码是CP936的,所以传上去后要用ICONV来转码。

[root@localhost t_girl]# iconv -f CP936 -t UTF-8 ytt.CSV -o ytt.new
[root@localhost t_girl]# chown mysql:mysql ytt.new 
[root@localhost t_girl]# cp -uf ytt.new ytt.CSV 
[root@localhost t_girl]# ls -sihl
total 56K
13797305 8.0K -rw-rw---- 1 mysql mysql   61 Apr 30 15:19 db.opt
30539777 8.0K -rw-rw---- 1 mysql mysql  383 Jun 19 09:54 show_user.frm
13797308  12K -rw-r--r-- 1 mysql mysql 4.5K Aug  9 14:59 ytt.CSV
13797306  16K -rw-rw---- 1 mysql mysql 8.5K Aug  8 17:39 ytt.frm
13797307  12K -rw-r--r-- 1 mysql mysql 4.5K Aug  9 14:57 ytt.new
[root@localhost t_girl]# sed -i 's/^/"/g' ytt.CSV 
[root@localhost t_girl]# sed -i 's/,/","/g' ytt.CSV 
[root@localhost t_girl]# sed -i 's/$/"/g' ytt.CSV 

用SED替换是为了用双引号来分割各个字段。






本文转自 david_yeung 51CTO博客,原文链接:http://blog.51cto.com/yueliangdao0608/92045,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
20天前
|
存储 缓存 安全
掌握Go语言:Go语言中的字典魔法,高效数据检索与应用实例解析(18)
掌握Go语言:Go语言中的字典魔法,高效数据检索与应用实例解析(18)
|
13天前
|
存储 关系型数据库 MySQL
MySQL引擎对决:深入解析MyISAM和InnoDB的区别
MySQL引擎对决:深入解析MyISAM和InnoDB的区别
28 0
|
1天前
|
Java
并发编程之线程池的应用以及一些小细节的详细解析
并发编程之线程池的应用以及一些小细节的详细解析
14 0
|
2天前
|
SQL 存储 关系型数据库
数据库开发之mysql前言以及详细解析
数据库开发之mysql前言以及详细解析
10 0
|
6天前
|
Java 关系型数据库 MySQL
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例
UWB (ULTRA WIDE BAND, UWB) 技术是一种无线载波通讯技术,它不采用正弦载波,而是利用纳秒级的非正弦波窄脉冲传输数据,因此其所占的频谱范围很宽。一套UWB精确定位系统,最高定位精度可达10cm,具有高精度,高动态,高容量,低功耗的应用。
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例
|
7天前
|
Java API 数据库
深入解析:使用JPA进行Java对象关系映射的实践与应用
【4月更文挑战第17天】Java Persistence API (JPA) 是Java EE中的ORM规范,简化数据库操作,让开发者以面向对象方式处理数据,提高效率和代码可读性。它定义了Java对象与数据库表的映射,通过@Entity等注解标记实体类,如User类映射到users表。JPA提供持久化上下文和EntityManager,管理对象生命周期,支持Criteria API和JPQL进行数据库查询。同时,JPA包含事务管理功能,保证数据一致性。使用JPA能降低开发复杂性,但需根据项目需求灵活应用,结合框架如Spring Data JPA,进一步提升开发便捷性。
|
10天前
|
SQL API 数据库
Python中的SQLAlchemy框架:深度解析与实战应用
【4月更文挑战第13天】在Python的众多ORM(对象关系映射)框架中,SQLAlchemy以其功能强大、灵活性和易扩展性脱颖而出,成为许多开发者首选的数据库操作工具。本文将深入探讨SQLAlchemy的核心概念、功能特点以及实战应用,帮助读者更好地理解和使用这一框架。
|
12天前
|
机器学习/深度学习 分布式计算 BI
Flink实时流处理框架原理与应用:面试经验与必备知识点解析
【4月更文挑战第9天】本文详尽探讨了Flink实时流处理框架的原理,包括运行时架构、数据流模型、状态管理和容错机制、资源调度与优化以及与外部系统的集成。此外,还介绍了Flink在实时数据管道、分析、数仓与BI、机器学习等领域的应用实践。同时,文章提供了面试经验与常见问题解析,如Flink与其他系统的对比、实际项目挑战及解决方案,并展望了Flink的未来发展趋势。附带Java DataStream API代码样例,为学习和面试准备提供了实用素材。
34 0
|
20天前
|
测试技术 API 智能硬件
语言模型在提升智能助手引用解析能力中的创新应用
【4月更文挑战第4天】苹果研究团队推出了ReALM,一种利用大型语言模型解决引用解析的新方法,提升智能助手理解用户意图和上下文的能力。ReALM将引用解析转化为语言建模问题,尤其擅长处理屏幕上的实体,比现有系统提升超5%,性能接近GPT-4但参数更少。其模块化设计易于集成,可在不同场景下扩展。然而,复杂查询处理和依赖上游数据检测器可能影响其准确性和稳定性。
63 6
语言模型在提升智能助手引用解析能力中的创新应用
|
16天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)

推荐镜像

更多