Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7562539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:25:57+00:00 2026-05-30T13:25:57+00:00

I have a MySql database with just over 30 Million rows, but some of

  • 0

I have a MySql database with just over 30 Million rows, but some of the rows (appropriately 3 million) are duplicate i am using the php script below to copy the database and check for duplicates, but its is running very slow its taken 3 days and its not even half way throught, is there anyway to speed it up? i’m running the script on the MySql Server itself.

    <?php

$dbhost = "localhost" ;


$con = mysql_connect("$dbhost","$dbuser","$dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$dbame", $con);

$server_self = $_SERVER['PHP_SELF'];
$rows_per_page = 1000;
$dbname_var = post1;




//paging script
$query = "SELECT count(*) FROM $dbname_var";         //change!!
//paging script



//PAGING SCRIPT
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
} // if


$resulta = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($resulta);



$numrows = $query_data[0];
$lastpage      = ceil($numrows/$rows_per_page);

$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
if ($pageno < 1) {
   $pageno = 1;
} // if

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$nextpage = $pageno+1;
$prevpage = $pageno-1;







$result = mysql_query("SELECT * FROM $dbname_var $limit");
while($row = mysql_fetch_array( $result )) {


$as = $row[1];
$ad = $row[2];
$af = $row[10];

//CHECK IF THE ROW ALREADY EXISTS IN THE TABLE
$resultdb1 = mysql_query("SELECT * FROM post_final WHERE
add1='$as' AND
add2='$ad' AND
add10='$af'");

$num_rowsdb1 = mysql_num_rows($resultdb1);

//IF IT DOSENT ADD IT!
if($num_rowsdb1 < 1) {

mysql_query("INSERT INTO post_final (add1,
 add2,
 add3,
 add4,
 add5,
 add6,
 add7,
 add8,
 add9,
 add10)
VALUES ('$row[1]',
 '$row[2]',
 '$row[3]',
 '$row[4]',
 '$row[5]',
 '$row[6]',
 '$row[7]',
 '$row[8]',
 '$row[9]',
 '$row[10]')");
} }







$nxt = $_GET['pageno'] + 1;



if ($_GET['pageno'] < $lastpage) {

print "<BODY>
<script type=\"text/javascript\">
<!--
window.location = \"/addnew.php?pageno=$nxt&lastpage=$lastpage\"
//-->
</script>
</BODY>
</HTML>\n";  }

?>

#   Column  Type    Collation   Attributes  Null    Default Extra   Action
 1  ID  int(10)         No  None    AUTO_INCREMENT    Change      Drop   More 
 2  add1    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 3  add2    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 4  add3    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 5  add4    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 6  add5    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 7  add6    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 8  add7    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 9  add8    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 10 add9    varchar(50) latin1_german2_ci       No  None          Change      Drop   More 
 11 add10   varchar(50) latin1_german2_ci       No  None          Change      Drop   More 

Action  Keyname Type    Unique  Packed  Column  Cardinality Collation   Null    Comment
 Edit    Drop   PRIMARY BTREE   Yes No  ID  10044279    A       
 Edit    Drop   add10   BTREE   No  No  add10   590839  A       
 Edit    Drop   add1    BTREE   No  No  add1    264323  A       
 Edit    Drop   add2    BTREE   No  No  add2    233587  A
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:25:58+00:00Added an answer on May 30, 2026 at 1:25 pm

    Use only SQL, there’s no need to take the data back and forth between SQL and PHP. Assuming you have a database db1 with table post_final, create database db2 create empty post_final table and do

    INSERT INTO `db2`.`post_final` (add1, add2, ...., add10) 
    SELECT DISTINCT add1, add2, ... , add10 FROM `db1`.`post_final`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pulling some data from mysql database using PHP, now I would like
I have just imported a huge MySQL database. Most fields are latin1_swedish_ci, and they
My MySQL database can store the euro symbol just fine (as I have tested
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a MySQL database table with a couple thousand rows. The table is
I have a mysql database which has grown to over 200 tables in it.
I have found many calculations here and some php examples and most are just
I just had a friend of mine look over some code I'm using to
I am trying to create a go-moku game using jquery,php, and mysql database. I
Below is part of a PHP database class someone else wrote, I have removed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.