How to write a script to insert large amounts of data in mysql? [closed]

Problem :

I am working on a database project where one of the requirements is that we must have 100,000 tuples of data. We originally were looking for general population data where each individual is represented by a tuple, but we quickly found out that sort of data isn't really available. No worries, we can create our own data!

So basically I need to write a basic script to just iterate through every tuple and insert basic stuff, like an ID(Just number them 1-100000), a set of random initials, a random income, and a random occupation from a list of 6 or so. Is this possible in mysql? I am really not excited about writing 100000 INSERT commands

Solution :

Something like this:

for i in range(1, 1000000)
    initials = ?
    income = ?
    occupation = ?
    sql = "insert into t(initials, income, occupation) values ('{0}', {1}, '{2}')".format(initials, income, occupation)

I'm not sure what values you want for the various fields. You can create lists of acceptable values and then use random() to choose from a list . . . or use random() to generate a numeric value.

It will take a little time to insert 1,000,000 rows. If this is an issue, write the data to a file and use load data infile.

Mysql Tutorials

Mysql Howto..

How to reference a table by id

How to save an array of dates read from mysql on php?

How to read data fromMysql table?

How to retrieve 10 latest DISTINCT IP's from a MySQL table?

How to change mysql column from html table with php scripting

Stackoverflows Tags system, How To

Implementing Mysql Joins. How to get results in same row?

MySQL: how not to repeat the column_definition for each column when adding multiple columns

How can i build a WCF+MySQL Server which can communicate with differents clients(differents OS)?

how to prevent mysql from createing mysql-bin.00000x files?

How to output items in Order in MySQL?

how to insert xml to mysql with php [duplicate]

how to improve select performance in mysql?

How to implement cascading deletion of hierarchical data in MySQL?

How to add auto-increment to column in mysql database using phpmyadmin?

How to get sum of mysql column using PHP as usable variable

How can access MySQL with Python?

how to create file download link to a file stored in MYSQL database with PHP?

How to query using LIKE clause in mysql using comparing to a varied string input?

MySQL: How to fetch data with left-join if column contains multiple ids?

MySQL how to check multiple values, and return the rows and information on what matched them

How to save canvas image to mySQL without php, jquery

How many rows are 'too many' for a MySQL table? [duplicate]

How to display ascending or descending for the contents shown in mysql

How to use LIKE for mysql search with JOIN and ORDER BY the count of most rows/votes in the vote table?

Connecting database in app without show interface at website

How to update Mysql using array in php in a dynamic way

how to store array values into single cell in mysql table using php?

How to convert a column data to a row in php mysql

How to know if the insert function to mysql is done successfully?