View Single Post

   
  #1 (permalink)  
Old 02-28-2008, 07:10 AM
Stefan Mueller
 
Posts: n/a
Default Why is my MySQL database so slow

I've created my first MySQL table 'mytable' with two fields (key_mytable,
code):
CREATE TABLE `mytable` (
`key_mytable` int(10) unsigned NOT NULL default '0',
`code` varchar(12) collate latin1_german1_ci default NULL,
PRIMARY KEY (`key_mytable`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci
COMMENT='mytable';

With the following PHP script I'd like to add 2000 entries.
<?php
...
\\ Delete all entries
$table = "mytable";
$query = "TRUNCATE " . $table;
mysqli_query($link, $query);

\\ Add entries
for ($i = 1; $i <= 2000; $i++) {
$table = "mytable";
$query = "INSERT INTO " . $table . " (key_mytable, code) VALUES ('" .
$i . "', 'test')";
mysqli_query($link, $query);
}
...
?>

But this is very very slow.
After 30 seconds (after around 600 entries) PHP stops and shows the
following error message:
[01-Dec-2005 01:33:41] PHP Fatal error: Maximum execution time of 30
seconds exceeded in D:\PHP\MyScript.php on line 35

What's wrong?
Stefan


Reply With Quote