I have insert 14.485 lines on MySQL like this:
INSERT INTO `bairros` (`id`,`cidade_id`,`descricao`) VALUES (1,8891,'VILA PELICIARI');
INSERT INTO `bairros` (`id`,`cidade_id`,`descricao`) VALUES (2,8891,'VILA MARIANA');
...
It took around 5 minutes.
I had to insert in another table 16.021 lines, same database, so for test I did this:
INSERT INTO `bairros` (`id`,`cidade_id`,`descricao`) VALUES (1,8891,'VILA PELICIARI'),(2,8891,'VILA MARIANA');
...
It took just a few seconds.
What is the difference, for the database, between the scripts? And why one is faster than the other?
The difference is that the first script contains 14,485 separate queries, each of which must be committed.
The second is a single query.