user3723326
user3723326

Reputation: 115

Move MySql database in Rails

I am working on a Rails application in Lubuntu. It has MySQL database at the back end. I want to move the application with the Database to my new Ubuntu OS. I can move the Rails project by using Git, but I am not sure how to move the MySQL database. I was wondering if there is a quick way to move the database. I would appreciate any help.

Thanks

Upvotes: 0

Views: 408

Answers (2)

Jeffy Mathew
Jeffy Mathew

Reputation: 580

You can move the data by taking a mysqldump.

mysqldump -u [user_name] -p  -h [hostname] [database_name] > [file_name.sql]

Use this in the terminal with the relevant attributes, upon success it will generate a MySQL dump file which you can later to use to restore your database to another machine. Also since the structure of the database is remaining the same, applying migrations from rails will show no changes, then you are good to work with it in the new machine.

Upvotes: 2

Cryptex Technologies
Cryptex Technologies

Reputation: 1163

Follow these steps:

1) For exporting the db dump into the local system

mysqldump -u [username] -p [db_name] > [sql_file_name.sql]

2) Make its tar for easily share with other system:

tar -czvf [any_name.tar.gz] [sql_file_name.sql]

3) Move it to the other system where you have to import it.

4) Untar the file:

tar -xzf [any_name.tar.gz]

5) Import database:

mysql -u [username] -p [db_name] < [sql_file_name.sql]

Upvotes: 0

Related Questions