Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the insertion speed of MySQL?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how much is the MySQL insertion speed". In the daily operation, I believe many people have doubts about the MySQL insertion speed. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how much is the MySQL insertion speed?" Next, please follow the editor to study!

Writing speed

Can MySQL insert 50w records per second?

With doubt, let's see how many records mysql can insert per second.

To answer this question, what are the factors that affect the speed of mysql insertion?

The speed of the hard disk, the speed of the network card, the amount of data written to the row, the location of the data in the hard disk, and so on.

Simple data, the insertion speed must be fast, complex insertion must be slow.

So simply this question is not easy to answer, the best way is to conduct a stress test, and finally find an average.

A test environment:

MySQL table structure

CREATE TABLE `user_ 10w` (`id` int (10) NOT NULL AUTO_INCREMENT, `name` varchar (20) DEFAULT NULL, `mobile` varchar (11) DEFAULT NULL, `add_ time` int (11) DEFAULT NULL, `groupid` tinyint (1) DEFAULT NULL, `login_ time` int (11) DEFAULT NULL, PRIMARY KEY (`id`) ENGINE=MyISAM AUTO_INCREMENT=4730016 DEFAULT CHARSET=utf8mb4

Computer configuration

4-core Intel (R) Core (TM) i3-8100 CPU @ 3.60GHz

Ssd 120g hard disk

two。 Start testing.

Description: stand-alone test, does not involve network card, the impact of network transmission

Test program php pdo

Include_once ("tool.php"); $dsn = 'mysql:dbname=demo;host=127.0.0.1'; $user =' root'; $pass = 'root'; try {$hand = new PDO ($dsn, $user, $pass);} catch (PDOException $e) {echo' Connection failed:'. $e-> getMessage ();} $query = $hand- > prepare ("insert into user_10w (name,mobile,add_time,groupid,last_login_time) values (?,?)"); $nong0; $count = 1000000; / / 100w $t = time (); echo 'start write,time is'. $t. "\ n"; while (true) {$nails; $name = Tool::getRandomStr (5); $mobile = Tool::getRandNum (9); $group = Tool::getRandNum (1); $rs = $query- > execute ([$name,'13'.$mobile,time (), $group,time ()]); if ($n > $count) break;} echo 'write end, time is'. (time ()-$t). "\ n"

1. No index, single process

Start write,time is 1593338798 write end, time is 50

Time-consuming 50s, average 2w/ seconds

two。 Add a normal index to name

Write end, time is 60 root@test:/data/php# php7 pdo.php start write,time is 1593393695 write end, time is 61

It is about 10 seconds slower, so the index will cause the insert to be slower because the index will be updated.

Load

3. Multi-process testing

A simple multi-process execution program is written with go.

Package main import ("os/exec"sync") var wg sync.WaitGroup func testRun (wg * sync.WaitGroup) {c: = exec.Command ("php7", ". / pdo.php") c.Run () wg.Done ()} func main () {var n int = 10 wg.Add (n) for

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report