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

  • Home
  • SEARCH
  • 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 8650743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:53:50+00:00 2026-06-12T13:53:50+00:00

I have a MySQL Table that looks like this: The SQL to create the

  • 0

I have a MySQL Table that looks like this:

MySQL Table: status

The SQL to create the structure is:

CREATE TABLE `status` (
`id` INT(11) NOT NULL,
`responseCode` INT(3) NOT NULL DEFAULT '503',
`lastUpdate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

It stores a unique id, responseCode, and lastUpdate. The responseCode is an HTTP Request response code: 404, 500, 503, 200, etc.

I have a URL to correspond to each id for which I make an HTTP request and record in this table the time I made the request and the response received.

The script makes this query against the status table:

SELECT id FROM status WHERE lastUpdate < 'XXXX' OR 
(responseCode != 200 AND responseCode != 404) 
ORDER BY id DESC LIMIT 100

Where XXXX would be a date where I decide that anything older than that date needs to be refreshed regardless of the response code. Further, I want to reattempt the HTTP request if I didn’t get a 200 or 404 regardless of the last lastUpdate date. I LIMIT to 100 because I only run 100 at a time, and then I have it sleep for a while and do another 100 later, and so on.

Anyways, all that’s fine, but what I want to do is populate the table ahead of time with say a series like this:

(1, 503, NOW()), (2, 503, NOW()), (3, 503, NOW()) ... (100000, 503, NOW())

Notice, only the ID is incrementing, but it may not necessarily start at 1 for my needs. I want the table pre-populated like this, because then the query above can keep grabbing id‘s for ones we need to reattempt, and I’d like to not have to ever insert anything more into the status table as the id‘s are finite and will not change (but there are many of them).

I tried using JAVA, (though PHP, C#, or whatever else is the same concept and doesn’t matter to me which language I use here):

PreparedStatement st = conn.prepareStatement("INSERT INTO status VALUES (?,default,default)");

for( int i = 1; i <= 100000; i++ ) {
    st.setInt(1,i);
    st.addBatch();
}

System.out.println( "Running batch..." );
st.executeBatch();
System.out.println( "Batch done!" );

This starts the inserts, but the issue is that it takes an extraordinary amount of time to populate the table (I don’t have an exact time, but it was running for hours). So, my question boils down to: is there an easy and efficient way to populate a MySQL table with a mass amount of rows like this?

  • 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-06-12T13:53:51+00:00Added an answer on June 12, 2026 at 1:53 pm

    Generally speaking, you can use any one or more of the following:

    • Start a transaction, do inserts, commit
    • Pack multiple values into a single insert into query
    • Drop any constraints before doing insert and reinstate constraints after the mass insert (except possibly primary key, not very sure about it though)
    • Use insert into ... select if suitable

    The first (using transactions) is most likely to help, but i’m not sure if it works on myisam tables, with innodb it does a very good job – I only use those when I’m forced to use mysql, I prefer postgresql.

    In your specific case, inserting 100000 rows of data, you could do the following:

    INSERT INTO status(id, responseCode, lastUpdate) SELECT @row := @row + 1 as row, 503, NOW() FROM 
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t,
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t2, 
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t3, 
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t4, 
    (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) t5, 
    (SELECT @row:=0) t6;
    

    Tested this on my machine, got:

    Query OK, 100000 rows affected (0.70 sec)
    Records: 100000  Duplicates: 0  Warnings: 0
    

    I’m pretty sure you can’t get much faster than that for 100000 rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table that looks like this: `id` int(10) unsigned NOT NULL
I have a mysql table that looks like this: id col2 col3 col4 1
I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have created this table with a sql query that looks like this $result
I have a table in MySQL That looks like the following: date |storenum |views
I have a mySQL table that has a column like this: ID ----- 0352
I have a table with a row that looks like this: ( 20091231 48498429,
I need to create MySQL tables that represent a tree structure like this: Root

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.