How to Copy a MySQL Database
There are several methods to replicate a MySQL database, and one common approach is as follows:
- Backup the source database using the mysqldump command.
- Create a dump of the source_database using the username and password, and save it as dump.sql.
- Create an empty target database on the destination server.
- Create a database named “target_database” with the specified username and password in MySQL.
- Import the backup files into the target database.
- Use the following command to import the dump.sql file into the target_database using MySQL: mysql -u username -p password target_database < dump.sql
This completes the operation of copying the source database to the target database.
Please note that the above methods are only suitable for small-scale databases or situations with a small amount of data. For larger databases, MySQL Replication can be used for more efficient database replication.