I'm attempting to import an SQL dump via PHP. I've the next code.

    @mysql_connect("localhost", "root", "root") or die("Cannot connect to DB!");
    @mysql_select_db("great_database") or die("Cannot select DB!");
    $query = file_get_contents('defaultDatabasePartOne.sql', FILE_USE_INCLUDE_PATH);
    $result = mysql_query($query);      

    $error = mysql_error();

Yes, it is properly loading my file, since it debugs $query, the file. I removed comments in the file, however it continues to have line breaks, this would not be an issue, wouldn't it?

I understand this error might have related to a timeout, however i went SET GLOBAL wait_timeout =99999999999 also it did not change anything and so i believe that is probably not it? I'm not familiar with SQL how do i fix this?

This is actually the example for @chris:

CREATE TABLE `access_tokens` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `token` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `user_id` int(11) NOT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `token` (`token`),
  KEY `user_id` (`user_id`)

Found this:

Heres the function i did previously do that operation: Thought i'd publish it simply for individuals who require it later on.

  • $url is the road to the sql file
  • $nowhost is dbhost
  • $nowdatabase is db
  • $nowuser is db user
  • $nowpass is db pass


function parse_mysql_dump($url,$nowhost,$nowdatabase,$nowuser,$nowpass){
    $link = mysql_connect($nowhost, $nowuser, $nowpass);
        if (!$link) {
           die('Not connected : ' . mysql_error());

        // make foo the current db
        $db_selected = mysql_select_db($nowdatabase, $link);
        if (!$db_selected) {
           die ('Can\'t use foo : ' . mysql_error());
   $file_content = file($url);
   foreach($file_content as $sql_line){
     if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
     //echo $sql_line . '<br>';

How large is the fact that dump? You may be exceeding the max_allowed_packet limit (the max size a question could be going client->server).

Too, keep in mind that b .sql file created by mysqldump consists of MULTIPLE queries. The PHP mysql motorists do not let greater than a single query statement to become performed using a single query() call. You may never have the ability to load a dump by doing this without parseing the dump file into individual queries.