Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit a01f2ad

Browse files
author
carlos
committed
python single thread vs node inserting in mysql
1 parent 9126bb8 commit a01f2ad

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TABLE IF NOT EXISTS `example` (
2+
`id` int(11) DEFAULT NULL,
3+
`data` varchar(40) DEFAULT NULL
4+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var mysql = require('mysql');
2+
// Create a connection to MySql Server and Database
3+
4+
var insert_random_element=function(){
5+
var connection = mysql.createConnection({
6+
host : 'localhost',
7+
port : 3306,
8+
database: 'node_test',
9+
user : 'root',
10+
password : 'admin'
11+
});
12+
connection.connect(function(err){
13+
if(err != null){
14+
console.error('Error connecting to mysql:' + err+'\n');
15+
}
16+
});
17+
18+
connection.query("insert into example (`data`) VALUES ( "+(new Date()).getTime()+");", function(err, rows){
19+
if(err != null) {
20+
console.error("Query error:" + err);
21+
} else {
22+
try{
23+
console.log(rows[0]);
24+
console.log("Success!");
25+
}catch(e){}
26+
}
27+
});
28+
connection.end();
29+
}
30+
31+
32+
for(var i=50;i-->0;)insert_random_element();
33+
//process.exit(code=0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#/usr/bin/env python
2+
3+
import time,mysql.connector
4+
5+
for i in xrange(50):
6+
conn = mysql.connector.connect(host= "localhost",
7+
user="root",
8+
passwd="admin",
9+
db="node_test")
10+
try:
11+
x = conn.cursor()
12+
x.execute("INSERT INTO example (data) VALUES (%s)" % time.time())
13+
conn.commit()
14+
conn.close()
15+
print "element inserted"
16+
except:
17+
print "errorrrrrrrrrrrrrr"

0 commit comments

Comments
 (0)