Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create New Database From SQL Dump File

Posted on 2008-06-23
6
Medium Priority
?
792 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 20

Accepted Solution

by:
virmaior earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

927 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