Do you know, you can import all the rows from a text file to mysql database - table rows at once. Today i will tell you how you can make rows in mysql database by importing a text file. This process is the fastest way to import data from a text file.

1. Login to Cpanel (

2. Click phpMyAdmin and then your database

3. Click "SQL" (Next to Structure)

4. Now you have to first create a table to import data from the text file. Put the below code and hit "Go" button:

CREATE TABLE ImportedWordList ( Word VARCHAR(200) )
5. Upload the text file to your server (public_html) and name it as import.txt

6. Now we have to create a php file. Open the text editor and insert the below code:

mysql_connect('localhost', 'user', 'pass') or die(mysql_error());  
mysql_select_db('db_name') or die(mysql_error());  
$lines = file('import.txt');  
$company_names = "";  
$insert_string = "INSERT INTO `ImportedWordList`(`Word`) VALUES"; 
$counter = 0; 
$maxsize = count($lines); 
foreach($lines as $line => $company) { 
$insert_string .= "('".$company."')"; 
if($counter < $maxsize){ 
$insert_string .= ","; 
mysql_query($insert_string) or die(mysql_error());
7. Change username, password, database name and file path (ex. /home/*user*/public_html/import.txt) in the above code and save it as import.php

8. Now upload the import.php to the same directory where your text file was uploaded. (public_html)

9. Thats it. Now run the file from a browser. (Ex.

All the rows from your text file will be insert into your database table.

For more info visit: