I created a database using 'CREATE DATABASE Gameshop;' for my class and I need to hand it in as an '.sql' file but, I don't know where to look for the file or how to create it.
I am worried I will lose all of my work if I attempt something and fail. Thank you!
-
2Possible duplicate of MySQL: How to export and import an .sql file from command line?Stuti Rastogi– Stuti Rastogi2017-05-12 04:46:04 +00:00Commented May 12, 2017 at 4:46
-
Is this on your own machine? What operating system are you using?kojow7– kojow72017-05-12 06:25:34 +00:00Commented May 12, 2017 at 6:25
Add a comment
|
2 Answers
In your command prompt (NOT mySQL command line):
Use $ mysqldump -u <username> -p<passwprd> db_name > db_backup.sql in order to dump the entire database on to an SQL file from the command line.
To import back use $ mysql -u <username> -p -h localhost db_name < db_backup.sql
See manual for more details.
6 Comments
Anthony Herrera
I get this error "ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump' at line 1" when i try to use mysqldump in the command prompt
kojow7
@AnthonyHerrera , Are you sure you are typing this at the command prompt of your OS and not in your MySQL server? Be sure not to use the $.
Kuldeep Dubey
You have to use shell command prompt not mysql command prompt
denny
'$' sign is useless
Anthony Herrera
It is in the mysqld prompt. how do i get to the shell command prompt without losing my work?
|
You could export your database using the export wizard of your Database IDE(MySQL Workbench,phpmyadmin, Sequel Pro etc...) or else if you are using command line for single database use
mysqldump database_name > database_name.sql
for Multiple databases
mysqldump --databases database_one database_two > two_databases.sql
for all databases on server
mysqldump --all-databases > all_databases.sql
6 Comments
Anthony Herrera
I get this error "ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump' at line 1" when i try to use mysqldump in the command prompt.
Kuldeep Dubey
could you post the sql statement and also are using simple command prompt or mysql command line. you need to use shell command prompt not mysql command prompt
Anthony Herrera
mysql command line. mysqldump -uch0mpy -p Gameshop > "C:\Users\ch0mpy\Desktop\backup.sql"
Stuti Rastogi
Don't use mysql command line. Use your normal command prompt.
Anthony Herrera
How do i get to the normal command prompt from mysql without losing all of my work?
|