The following php script takes about 22 seconds to execute. Is it normal? If not what would cause it to execute slowly?
$conn = mysql_connect('localhost', 'root', '123');
mysql_select_db('mydb', $conn);
$time1 = time();
for ($i=1;$i<500;$i++) {
mysql_query("Insert into accounts(id, username, email, password) VALUES(\"$i\", \"$i\",\"$i\",NOW())");
}
print time() - $time1; // return ~22
Edit: Table structure:
CREATE TABLE IF NOT EXISTS `accounts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`email` varchar(200) NOT NULL,
`password` varchar(20) NOT NULL,
`status` varchar(10) DEFAULT 'pending',
`email_newsletter_status` varchar(3) DEFAULT 'out',
`email_type` varchar(4) DEFAULT 'text',
`email_favorite_artists_status` varchar(3) DEFAULT 'out',
`created_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7500 ;
This code is just to test insert speed. Using the Zend framework(insert method of Zend_Db) I get a similar result, so I think it's relevant to mysql and not php code
Edit2: I know that there is much better ways to execute this query, but I want to know why this one is so slow.