Reputation: 403
I am working on Linux (Ubuntu), and I want to export the whole schema from .sh file to .sql in order to open it in MySQL Workbench - but how can I do it?
I have tried with mysqldump
but it doesn't work, I wrote this command after opening .sh database, but I am not sure if it has some influence.
Command line in terminal:
mysql> mysqldump -uuser -ppassword db > db.sql
And it doesn't work - MySQL syntax error displays after that
Upvotes: 0
Views: 2738
Reputation: 24
1.Install mysql-client which includes mysqldump
user@local:~$ sudo apt-get install mysql-client-5.1
2. backup database
user@local:~$ mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
3. if you need you can import
user@local:~$ mysql -u root -p[root_password] [database_name] < dumpfilename.sql
Upvotes: 1
Reputation: 6854
Here .sh means a script file extension in which you will write your commands and .sql means a backup/dump file.
Example
Execute below command on linux prompt-
sudo vi backup_script.sh
It will open a blank file you can write your script here like -
cd /root/backup/
mysqldump -uroot -proot123 mydb > /root/backup/mydb.sql
Now save this file by Esc + : + wq
Note: backup folder should exist in root else you can create by below command-
mkdir /root/backup
Now you can execute backup_script.sh by below command-
sh backup_script.sh
It wil take your mydb database backup at /root/backup/ path.
Upvotes: 1