This article introduces an example code that uses PHP to delete duplicate records in the MySQL database. Friends in need can refer to it.
Method: Create a new table and directly import unique data records. The database used in this article is: test_db, and the temporary table is: test_tab. Example: <?php /** * 删除数据库中重复记录 * edit bbs.it-home.org * at 2013/6/25 */ set_time_limit(13600); //设置时间 $conn = mysql_connect('localhost','root',''); //连接数据库 mysql_select_db('test_db',$conn); mysql_query("set names 'gbk'"); $query = mysql_query("select min(id) as mid from my_shuju group by title"); while($row = mysql_fetch_array($query)) { mysql_query("INSERT into test_tab select id,cid,title,cat,level3,cname from taobaoguanjianci where id=$row[mid]"); } ?> Copy after login Instructions: Pay attention to the usage of the set_time_limit() function. If there is a lot of data, it may time out. Use this function to set the timeout limit. |