Move MySql database in Rails - mysql

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

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.

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]

Related

How to transfer MySQL database from AMPPS to XAMPP vm Stack

I hope you can help me - I used to use AMPPS, but unfortunately due to the Big Sur update it no longer works. so downloaded xampp vm stack. Now can't get a database I need.
I have gone into the Ampps folder and copied out the relevant physical database but copying this into the xampp folder it won't let me. I have attempted to change the permission via chmod -R 777 /Users/samjacksom/.bitnami/stackman/machines/xampp/volumes/root/var/mysql and via get info both won't allow me to do so.
Would anyone please have a solution to have I can get my database from the old Ampps?
UPDATE:
I have got a Catalina Virtual Machine running with Ampps. And, transferred the files onto there. For the database I copied the db folder from the var folder on ampps on my host to the vm location.
However, when I go into phpmyadmin the database is not unfortunately visible. Could someone advise how I can physically migrate a database?
why don't you just use mysqldump?
$ mysqldump -u [user] -p [database_name] > [filename].sql
or to get a backup of the entire database:
$ mysqldump --all-databases --single-transaction --quick --lock-tables=false > full-backup-$(date +%F).sql -u root -p
then you can restore your backup on new stack just by running:
$ mysql -u [user] -p [database_name] < [filename].sql

MySQL data backup?

I have an database with tons of data in it.
I also wrote a new program that will change the data in the database.
Is there any way to make a copy of the database before i run my program?
Or is there any other solution?
What I'm thiking is making a copy of the database,
Run the program, which modified the main database. If things goes wrong, how do I use my copied database data to revert the main database?
Please provide steps and commands on linux. I'm new with the database mysql and its commands.
You can use the mysqldump command to make a backup of your database and overwrite the backup file everytime
mysqldump -u <user> -p <db> > dump.sql
Read the following link this will tell you how to dump your database via different ways and restore it.
http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/
Basic command to dump a single database is:
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
Is there any way to make a copy of the database before i run my program?
Yes, there's. You have to use the client utility mysqldump before run you app.
It is something like
shell> mysqldump [options] > dump.sql

Exporting a table in mysql

I am doing some prototyping and so created a database with a few tables and dependencies. The project became bigger than I thought and now want to clean up the names, dependencies etc and so want to create the DB anew. But I don't want to go through the whole process of creating individual tables again, instead I want to start with what I have, clean the creation scripts up and run them if possible. Is there a way I can export all the scripts to create the DB and tables? Are there tools or mysql command line options to do this?
Thanks,
-S
This can get you started:
mysqldump -u user -ppassword -h host --no-create-db --no-data [other options] old_database > dump.sql
then you can edit the dump file for any necessary changes and import back into the new database:
mysql -u user -ppassword -h host new_database < dump.sql
More information about the mysqldump #MySQL Reference Manual
I recommend you to look at MySql WorkBench
It can do everything you need
Here's the list of all the features
Reverse Engineer from Live Database
Reverse Engineer from SQL Script
Also, good to mention that it's free (community version)

Dump all databases and reimport on another server?

It's quite simple really, I just can't figure out the syntax.
I want to replicate my server setup on another server.
I can dump all my databases with
mysqldump -uroot -p --alldatabases > all.sql
But how do I import ALL of those into a brand new mysql setup on another server?
mysql -u root -p < all.sql
will do
From command line:
mysql -uroot < all.sql
ps. If you want to see what statement is executed right now you should -v.
if the database servers are both near enough the same version, you could simply rsync the /var/lib/mysql directory over.
rsync /var/lib/mysql root#destination.server.com:/var/lib/ -a
Edit: Please note that there are some issues with this approach which require some additional steps:
http://verens.com/2016/05/11/quick-method-to-clone-a-mysql-database/
mysql -u root -p
that command will open the mysql interactive console, where you'd do this:
source all.sql
execute the dump file from shell (dump file should contain the CREATE DATABASE syntax)
mysql -uroot < /path/to/file.sql
or execute from mysql
source /path/to/file.sql

How do I upload new data-base structure into mysql from my development db?

we've been making changes in the MySQL database, adding tables, columns and so forth and I have a development/staging site and production. All are MySQL, staging and production hosted remote.
How do I export the table structure and bring it into the production environment?
I have been using phpMyAdmin to administer it to date.
On local dev system:
$ mysqldump -u username -p databasename > export.sql
On remote system:
$ mysql -u username -p databasename
mysql> source pathto/export.sql
Check out mysqldump, a command line tool that comes with MySQL, here:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Using it, you can take a snapshot of both the structure and the data of your database and import it elsewhere.