Zen Cart Logo
Forums / Installing on a Linux/Unix Server / Import local backup into new database

Import local backup into new database

Locked

Views: 2,255

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
22 Dec 2007, 8:58 PM
#1
dharma avatar

dharma

Totally Zenned

Join Date:
Nov 2006
Posts:
505
Plugin Contributions:
0

Import local backup into new database

I need to import data from a local backup into a new database.

I created a new MySQL database and new name for it. Unfortunately I did not enable drop table:oops:, when I backed up my old database.

When I try to import my old data into a new database, it errors out and states that database exists already. (my old database is still up, but I do not want to delete or merge due to some changes)

I have my local backup as a .sql file which I downloaded with phpmyadmin, with these settings: see jpeg

and I also have a .txt file from a telnet/SSH dump but it also contains my old database name.

any advice?

23 Dec 2007, 9:38 PM
#2
geixa avatar

geixa

New Zenner

Join Date:
May 2007
Location:
Florida
Posts:
18
Plugin Contributions:
0

Re: Import local backup into new database

Hi there,
A few questions-
is your new database (in which you are trying to IMPORT data) totally empty?
Or are there tables in it? Specifically, did you install and unpack ZenCart's tables to this new database?

In your screen shot it appears you did not check 'Save as file', so generally if you leave that unchecked it opens the file... then did you save it?

as a test, in phpmyAdmin, create a totally new database. leave it empty. try to import your sql backup. do you still get an errror?

24 Dec 2007, 3:29 PM
#3
dharma avatar

dharma

Totally Zenned

Join Date:
Nov 2006
Posts:
505
Plugin Contributions:
0

Re: Import local backup into new database

I think this is my issue, with all my backups of my old database (dumped from phpmyadmin) with above settings (save as file was checked sorry) this line exists "create database"

-- phpMyAdmin SQL Dump
-- version 2.9.1.1
-- http://www.phpmyadmin.net
-- 
-- Host: MySQL.XXXX.com
-- Generation Time: Dec 07, 2007 at 09:34 AM
-- Server version: 4.0.27
-- PHP Version: 4.4.4
-- 
-- Database: `XXXXX-db101`
-- 
CREATE DATABASE `XXXXX-db101`;
USE XXXXX-db101;

-- --------------------------------------------------------

-- 
-- Table structure for table `address_book`

etc..

My new database db102 is empty, but when I try to import from my local file I get an error that that database exists already (db101).

I must import from my saved file, as the server db101 is possibly messed up.

A further mystery is why when I back up my database now, with the same settings the CREATE DATABASE XXXXX-db101;
USE XXXXX-db101; is gone.

I have in addition to the .sql file a text file which I dumped from telenet, which only has this in the header:

-- MySQL dump 9.11
--
-- Host: mysql.XXXXX.com    Database: XXXXX-db101
-- ------------------------------------------------------
-- Server version	4.0.27-log

--
-- Table structure for table `address_book`

Should I import just the text file with telenet into the empty db102? am I stuck with the name of the old database?

Or Simply change the name of my existing database db101 to TEMP.....create a new empty database with the same name db101..import from my saved file...download again with DROP table and hopefully not the "create database" part and upload into a new empty database db102 and restore the old database name from TEMP back to db101?

24 Dec 2007, 4:31 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Import local backup into new database

There's an FAQ on this topic:
https://www.zen-cart.com/tutorials/index.php?article=103

Pay attention to the "NOTE" in step 3 ... if you haven't already selected your database before exporting, the create-database stuff will be inserted into your export ... which can cause confusion and permissions problems when importing later.

24 Dec 2007, 9:06 PM
#5
dharma avatar

dharma

Totally Zenned

Join Date:
Nov 2006
Posts:
505
Plugin Contributions:
0

Re: Import local backup into new database

DrByte:

There's an FAQ on this topic:
https://www.zen-cart.com/tutorials/index.php?article=103

Pay attention to the "NOTE" in step 3 ... if you haven't already selected your database before exporting, the create-database stuff will be inserted into your export ... which can cause confusion and permissions problems when importing later.

I guess that was my error. Now I am stuck with "create database" in the last back up of my site.

I need to import this file into a new database, any suggestions on what to do?

This is the only thing that I can think of:

"Or Simply change the name of my existing database db101 to TEMP.....create a new empty database with the same name db101..import from my saved file...download again with DROP table and hopefully not the "create database" part and upload into a new empty database db102 and restore the old database name from TEMP back to db101?"

25 Dec 2007, 7:56 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Import local backup into new database

Most hosts don't allow you to create databases via direct SQL commands, because they control the security at a higher level.

Thus, your best solution is to simply remove the "CREATE DATABASE xxxxxxx" and "USE xxxxxxxx" statements from your SQL backup file.
Then import it to your new database.

25 Dec 2007, 8:13 AM
#7
gsis avatar

gsis

Zen Follower

Join Date:
Jun 2007
Posts:
140
Plugin Contributions:
0

Re: Import local backup into new database

Using a decent text editor (e.g. Notepad++) remove the Create Database statement from the SQL file. You can download Notepad++ from http://notepad-plus.sourceforge.net - it's free.

Create the new database by whatever means your host allows, open it and import the edited SQL file.

There may also be a 'Set' statement right at the end of your SQL dump that generates an error. I just ignore it because the import will have done everything it needs to by then - unless you hit a new problem.

25 Dec 2007, 5:33 PM
#8
dharma avatar

dharma

Totally Zenned

Join Date:
Nov 2006
Posts:
505
Plugin Contributions:
0

Re: Import local backup into new database

Thank you both for your help, I will remove this statement, with my text editor:

CREATE DATABASE `XXXXX-db101`;
USE XXXXX-db101;

then the header will look like this:

-- phpMyAdmin SQL Dump
-- version 2.9.1.1
-- http://www.phpmyadmin.net
-- 
-- Host: MySQL.XXXX.com
-- Generation Time: Dec 07, 2007 at 09:34 AM
-- Server version: 4.0.27
-- PHP Version: 4.4.4
-- 
-- Database: `XXXXX-db101`
-- 


-- --------------------------------------------------------

-- 
-- Table structure for table `address_book`

Do I need to delete anything else? any of ```

around the delted statement? or name of the old database
Database: XXXXX-db101


Sorry to ask such newbie questions..and hitting everyone over the head with the obvious :bangin: I just don't want to make any mistakes when it comes to the database...

Oh and Merry Christmas!
25 Dec 2007, 5:36 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Import local backup into new database

Most of the time, two dashes starting a line in a SQL file are considered to be comments.
So, you should be able to leave those alone safely.