Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a '.sql' file

Tags:

sql

mysql

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!

like image 854
Anthony Herrera Avatar asked Sep 15 '25 19:09

Anthony Herrera


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.

like image 163
Stuti Rastogi Avatar answered Sep 18 '25 09:09

Stuti Rastogi


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
like image 24
Kuldeep Dubey Avatar answered Sep 18 '25 10:09

Kuldeep Dubey