Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

restore mysql server question

Posted on 2014-01-16
3
284 Views
Last Modified: 2014-01-16
Hello,
  I have a database already created. Now, I would like to restore a backup copy. Does the commands MySQL -<id> -p <database> < backup.sql delete the existing database and then create a new one or do I have to do the following

1: delete the existing DB
2: Create the database
2: restore the backup

Thanks for your help
0
Comment
Question by:SiemensSEN
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 200 total points
ID: 39786099
Whenever I have done this, the database (schema) remains because the first line of the backup SQL file usually is as follows.
CREATE DATABASE  IF NOT EXISTS `db_name`;
USE `db_name`;

Open in new window


If you want to create a new database, you can change the top two lines of the code.  If I remember correctly, you can remove them and in the Workbench the new schema option will work.  Otherwise, it ignores that because of the USE schema name statement.
0
 

Author Closing Comment

by:SiemensSEN
ID: 39786205
Thanks
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39786693
It depends on your database dump file. E.g. using mysqldump, it is possible to request a "drop database" in the dump, using --add-drop-database
So have a look at the beginning of your backup.sql and if you can see something like "drop database ..." then you don't have to explicitly drop it.

As for creation, there's a similar option --no-create-db; unless invoked this way the "create database" will be present in the dump. Look for it.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Connect MySql database to wordpress site 3 80
PHP: Insert Data into MySQL 5 56
SubQuery link 4 36
CLI command keep running after close 7 36
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question