Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insertion into database

Tags:

mysql

insert

I have to write into MySQL database a lot of data for about 5 times per second. What is the fastest way: insert each 1/5 of second or make a queue and insert all stored data each ~5 seconds? If the second way is better - is it possible to insert into 1 table using 1 request a few rows?

like image 259
Max Frai Avatar asked Jun 12 '12 07:06

Max Frai


People also ask

What is insertion in database?

Data insertion is the process of inserting rows into a table. The data insertion methods and an example of specifying SQL statements are shown as follows. Data insertion methods. The INSERT statement is used to insert rows.

How do you insert data into a database table?

Simple INSERT statement to add data to the table. Use INSERT Statement to add multiple rows in the table. INSERT INTO SELECT clause to insert the output generated by the SELECT query. INSERT IGNORE clause to ignore the error generated during the execution of the query.

How do you insert data in SQL?

If you want to add data to your SQL table, then you can use the INSERT statement. Here is the basic syntax for adding rows to your SQL table: INSERT INTO table_name (column1, column2, column3,etc) VALUES (value1, value2, value3, etc); The second line of code is where you will add the values for the rows.

What is insert into in SQL?

The INSERT INTO statement is used to insert new records in a table.


2 Answers

Considering the frequency of the insertions Its better to go with the second approach that is queuing and than adding at one go.!

But You should consider these scenarios first :

  1. Is your system Real Time.? Yes then what is the maximum delay that you can afford (As it'll take ~5 seconds for next insertion and data to be persisted/available)?

  2. What are the chances of Incorrect values/Errors to come in data, as if one data is incorrect you'll loose rest all if the query has to fail.

like image 119
Anuj Patel Avatar answered Sep 29 '22 04:09

Anuj Patel


Using multiple buffer pools with innodb_buffer_pool_instances. it can depend on number of cores onmachine. Use Partitioning of table.
You can collectively insert data using XML.

like image 33
Romil Kumar Jain Avatar answered Sep 29 '22 04:09

Romil Kumar Jain