LiveEn
LiveEn

Reputation: 3253

import a large mysql database using php

im having a mysql database which around 300mb but unfortunately i cant import this file to my web host using phpmyadmin and i dont have shell access.

i tried the below alternatives

MySQLDumper

bigdump

but could get it inserted to the database.

The database has been uploaded to a folder in .sql format. is it possible to create a php script to read the .sql file and execute the queries?

the sql file was dumped using mysqldump.

below is the format. (please not that i have removed some lines coz there are so many)

DROP TABLE IF EXISTS `prime_lands`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `hotels` (
  `hotel_id` int(11) DEFAULT NULL,
  `chain_id` int(11) DEFAULT NULL,
  `chain_name` varchar(100) DEFAULT NULL,
  `brand_id` int(11) DEFAULT NULL,
  `brand_name` varchar(100) DEFAULT NULL,
  `hotel_name` varchar(100) DEFAULT NULL,
  `hotel_formerly_name` varchar(100) DEFAULT NULL,
  `hotel_translated_name` varchar(100) DEFAULT NULL
...........
)

-- Dumping data for table `prime_lands`
--

LOCK TABLES `prime_lands` WRITE;
/*!40000 ALTER TABLE `prime_lands` DISABLE KEYS */;

INSERT INTO `prime_lands` VALUES (1,421,'Samed Resorts Group',921,'Samed Resorts Group','Sai Kaew Beach Resort','','Sai Kaew Beach Resort',.......................)

....................................

Upvotes: 0

Views: 1687

Answers (1)

user557846
user557846

Reputation:

should work:

$run=   exec ('mysql -u username -p password database_name < filename.sql ', $out);
var_dump($run);
var_dump($out);

May be better for debugging:

$out = shell_exec('mysql -u username -p password database_name < filename.sql');
var_dump($out);

as a one off you may be able to ask your host to run the command for you, most 'nice' hosts would help you out with this.

Upvotes: 2

Related Questions