Sunday, May 22, 2016

Transfering SQL database between two linux servers

Process for moving a database between two linux servers running mysql.

Target server may or may not have the database created.  example used uses phpmydmin create database to create the empty database.

Use mysqldump to create an ".sql" file with the data from the database.  Example here is for an RSS reader application, and keeps track of the rss feeds for doing deltas for the read presentation.

Note for sql the password and user id are for the mysql users and the password on the mysql server.  They are not linux account passwords.  The commands can be performed from any userid with access to the mysql commands, since the database is worked via the mysqldump command to the mysql socket.  Access to the actual files is not required, since the work is done on those files by the mysql server.

backup:

 mysqldump --password=<some-password> -u <userid> rss > 2016-0522-rss-mysqldump.sql

create database in phpmyadmin: 

Databases->Create new Database [enter rss in name field] (Create)

restore:

mysql -u <userid> --password=<password> rss < 2016-0522-rss-mysqldump.sql


No comments:

Post a Comment