php - How to Update 1,000,000 data in my sql database in less time? -


i need update , insert around 1 million data in mysql data base, when using following code takes more time. please suggest how can update , insert data fastly?

include('db.php'); include('functions.php'); $functions=new functions();  set_time_limit(0);  $column="rank"."_".date("y-m-d");  $count=$functions->get_row("select count(id) ct alexa_filename status=1");  if($count->ct==100){       $alexas=$functions->get_result("select distinct (`sitename`),`$column` `top-2m`  `status`=0 limit 100" );       if(!empty($alexas)){           foreach($alexas $alexa){               $site_name=$alexa->sitename;               echo $site_name;               $rank=$alexa->$column;               $table=$functions->find_table_name($site_name);               $count=$functions->get_row("select count(site_name) ct `$table` site_name='$site_name'");               if($count->ct==0){                     $functions->set_query("insert `$table`( `site_name`, `other_id`, `response`, `category`, `updated`, `site_update`, `wot_update`, `social_update`,                                                                    `google_update`, `server_update`, `alexa_update`, `backlinks_update`, `antivirus_update`, `key`, `desc`, `google_backlink`, `images_url`,                                                                                                                         `images`, `tag`, `view_count`, `title`, `api_update_time`, `table_name`, `user_added_similar`, `auto_similar`, `comments`, `status`) values                                                                    ('$site_name',0,0,0,0,0,0,0,0,0,$rank,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)");                 $functions->set_query("update `top-2m` set `status`=1 sitename ='$site_name'");               }else{                  $functions->set_query("update  `$table` set `alexa_update`=$rank site_name='$site_name'");                        $functions->set_query("update `top-2m` set `status`=2 sitename ='$site_name'");               }           }       }else{           mail("aaa@aaa.com","alexa_cron_update_status","aaarank succes updated");       }  } 

  • you can insert/update multiple rows using insert ... on duplicate key update.
  • reindex database.
  • use prepared mysql statements.
  • also if using linux/ubuntu try use terminal instead of browser. make lot difference.

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -