Blog
Browsing all articles in PHP / MYSQL
How to import large mysql dump to database? or Fastest mysql dump importer
Hey guys, it is difficult to import large mysql dump file to database. See below for how to import mysql dump using only one file.
Step 1: Download dump file. (e.g. demodb.sql).
Step 2: Change connection, username, password, database variable values.
Step 3: Change dump file name with proper path.
Step 4: Run this page.
Import mysql dump file code.
| PHP | | copy code | | ? |
| 01 | <?php |
| 02 | $host ="Your Host"; // Change host (e.g localhost) |
| 03 | $dbusername ="Database username"; // Change Database Username |
| 04 | $dbpassword ="Database password"; // Change Database Password |
| 05 | $database ="Your database"; // Change Database |
| 06 | $dumpfile = "Your Dump file"; // Set dump file path (e.g. demodb.sql) |
| 07 | |
| 08 | mysql_connect($host,$dbusername,$dbpassword); |
| 09 | mysql_select_db($database); |
| 10 | $file = fopen($dumpfile, 'r'); |
| 11 | print '<pre>'; |
| 12 | print mysql_error(); |
| 13 | $temp = ''; |
| 14 | $count = 0; |
| 15 | |
| 16 | while($line = fgets($file)) { |
| 17 | if ((substr($line, 0, 2) != '−−') && (substr($line, 0, 2) != '/*') && strlen($line) > 1) { |
| 18 | $last = trim(substr($line, −2, 1)); |
| 19 | $temp .= trim(substr($line, 0, −1)); |
| 20 | if ($last == ';') { |
| 21 | mysql_query($temp); |
| 22 | $count++; |
| 23 | $temp = ''; |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | echo mysql_error(); |
| 28 | echo "Total {$count} queries fire(s).\n"; |
| 29 | echo "Enjoing this fastest mysql dump importer..\n"; |
| 30 | echo '</pre>'; |
| 31 | ?> |
Enjoying this fastest mysql dump importer.
Search the site
Our Services
Shree Gokul Infotech Like Box
Tags
20 SEO Tips
Adaptive Images
Avoid SEO things
Best Javascript Library
Best Javascript Library list
Best Practice with Title Tag
Best SEO Tips
Convert SWF files to HTML5
CSS Tricks
Deliver small images to small devices
Good Practice with Title Tag
Google Code
Google Labs
Google Web Fonts
How many things to avoid in SEO
HTML5
HTML Title Tag
Importance of meta tags in SEO
Insert Font in CSS
Javascript
Javascript Framework list
large images to large browser windows
Meta description in SEO
Meta keywords in SEO
Meta Tags
Meta Title
Project from Matt Wilcox
SEO
SEO - The Main Body Text
SEO friendly Content
SEO friendly content manner
SEO friendly Content tips
SEO general Tips
SEO navigation
SEO Tips
SEO Tips For Avoid
Serch Engine Optimization general tips
small images to small browser windows
Spider Friendly Navigation
Swiffy
Swiffy Example
Things To Avoid Website Tips SEO Tools
Tips SEO navigation
Title Tag
Title Tag in SEO

November 20, 2011 in