如何提高Mysql语句插入性能
在表中已有大量的index的情况下插入大量数据,可以采用先将索引删除,然后再插入数据,然后再重新建立索引。之所以这样会快是因为???
7.2.14 Speed of INSERT Statements
The time to insert a record is determined by the following factors, where the numbers indicate approximate proportions:
* Connecting: (3)
* Sending query to server: (2)
* Parsing query: (2)
* Inserting record: (1 x size of record)
* Inserting indexes: (1 x number of indexes)
* Closing: (1)
This does not take into consideration the initial overhead to open tables, which is done once for each concurrently running query.
The size of the table slows down the insertion of indexes by log N, assuming B-tree indexes.
You can use the following methods to speed up inserts:
* If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is much faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a non-empty table, you may tune the bulk_insert_buffer_size variable to make it even faster. See section 5.2.3 Server System Variables.
* If you are inserting a lot of rows from different clients, you can get higher speed by using the INSERT DELAYED statement. See section 14.1.4 INSERT Syntax.
* With MyISAM tables you can insert rows at the same time that SELECT statements are running if there are no deleted rows in the tables.
* When loading a table from a text file, use LOAD DATA INFILE. This is usually 20 times faster than using a lot of INSERT statements. See section 14.1.5 LOAD DATA INFILE Syntax.
* With some extra work, it is possible to make LOAD DATA INFILE run even faster when the table has many indexes. Use the following pr
相关文档:
MySQL :: Linux 下自动备份数据库的 shell 脚本
Linux 服务器上的程序每天都在更新 MySQL 数据库,于是就想起写一个 shell 脚本,结合 crontab,定时备份数据库。其实非常简单,主要就是使用 MySQL 自带的 mysqldump 命令。
脚本内容如下:
#!/bin/sh
# File: /home/mysql/backup.sh
# Database info
DB_NAME=" ......
DATE_FORMAT(date,format)
根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December)
%W 星期名字(Sunday……Saturday)
%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)
%Y 年, 数字, 4 位
%y 年, 数字, 2 位
%a 缩写的星期名字(Sun&h ......
参数篇
作/译者:吴炳锡,来源:http://imysql.cn & http://imysql.cn/blog/3208 转载请注明作/译者和出处,并且不能用于商业用途,违者必究。
介绍:
InnoDB给MySQL提供了具有提交,回滚和崩溃恢复能力的事务安全(ACID兼容)存储引擎。InnoDB锁定在行级并且也在SELECT语句提供一个Oracle风格一致 ......
好久没有整理东西,感觉自己越来越懒,正好近期有个MYSQL的项目(一个ORACLE的应用迁移到MYSQL),以前没有接触过MYSQL,但是也知道MYSQL数据库目前广泛的应用在各种个人、商务系统中,各种技术都比较成熟。把自己学习的一些过程总结一下,该文章设计到的内容都没有做太详细的阐述,只是一个简单的入门手册。
  ......