Solved

Create New Database From SQL Dump File

Posted on 2008-06-23
6
785 Views
Last Modified: 2010-04-21
Experts, I need to create a MySQL database from a .sql file created by using the sqldump command. I'm new to MySql and am not exactly sure the command to create the new database from this file. Also, do I need to manually setup the user and permissions?

Thank you for your help!

~ C
0
Comment
Question by:clickclickbang
  • 2
  • 2
  • 2
6 Comments
 
LVL 20

Expert Comment

by:virmaior
ID: 21847166
the command to create a table is
...

CREATE TABLE


you can actually just append this to  the front of a SELECT statement and it will make a table...  The field design might prove to be very sub-optimal, but you can change that later.

I would highly recommend using phpmyadmin to see what is going on as you do this.
0
 
LVL 8

Expert Comment

by:CoyotesIT
ID: 21847339
To create a database you simply issue the statement


CREATE DATABASE <database_name>;

Use the following with caution and only if you are sure you want to drop and recreate the database if it already exists:

DROP DATABASE IF EXISTS <database_name>;

Then you would run your CREATE statements.

You can always take a look at the output from using the mysqldump command to see how MySQL builds the sql script for that database which will aid in getting your solution built.

Hope that helps!

0
 
LVL 1

Author Comment

by:clickclickbang
ID: 21856087
Thank you for your posts. What I am trying to figure out is how to execute the SQL from the dump of SQL created via the dump command.

1) What is the syntax for targeting the .sql file created via the dump to re-create the database?

2) Is there anything I need to do before I re-create the database? (set user permissions, etc.)

Thank you for your help!

~ C
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 20

Accepted Solution

by:
virmaior earned 500 total points
ID: 21856161
(2) if you want to use the command line to do it, then you'll probably login as the root user anyway (which means  you won't initially need to set any permissions to create the tables).

(1) http://articles.techrepublic.com.com/5100-10878_11-5259660.html
mysql -u root -psecret -D stocks2 < stocksdb.sql

where
root is the username,
secret is the password,
stocksdb.sql is the file you are loading from and
stocks2 is the database you want

your values should of course be different for these items.




0
 
LVL 8

Expert Comment

by:CoyotesIT
ID: 21856688
Oh I see, sorry yes Virmaior's post is how you do it.

Good luck!
0
 
LVL 1

Author Closing Comment

by:clickclickbang
ID: 31469791
Thanks!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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