![]() In the following example the first command will create a database named database_name and then it will import the dump database_name.sql into it: mysql -u root -p -e "create database database_name" mysql -u root -p database_name < database_name.sql Restore a Single MySQL Database from a Full MySQL Dump # ![]() If the database already exists, first you need to delete it. In most cases you’ll need to create a database The command general syntax is as follows: mysql database_name < file.sql You can restore a MySQL dump using the mysql tool. The command above will create a file with the following format database_name-20180617.sql Restoring a MySQL dump # To the backup filename: mysqldump database_name > database_name-$(date +%Y%m%d).sql If you want to keep more than one backup in the same location, then you can add the current date Utility, and redirect it to a file as shown below: mysqldump database_name | gzip > database_ Create a Backup with Timestamp # To do that simply pipe the output to the gzip If the database size is very large it is a good idea to compress the output. ![]() Create a Compressed MySQL Database Backup # The command above will create a separate dump file for each database using the database name as the filename. The mysqldump utility doesn’t provide an option to backup all databases to separate files but we easily achieve that with a simple bash FOR loopįor DB in $(mysql -e 'show databases' -s -skip-column-names ) do mysqldump $DB > " $DB. Backup all MySQL databases to separate files # Same as with the previous example the command above will create a single dump file containing all the databases. Use the -all-databases option to back up all the MySQL databases: mysqldump -u root -p -all-databases > all_databases.sql The command above will create a dump file containing both databases. mysqldump -u root -p -databases database_name_a database_name_b > databases_a_b.sql Each database name must be separated by space. To backup multiple MySQL databases with one command you need to use the -database option followed by the list of databases you want to backup. If you are logged in as the same user that you are using to perform the export and that the user does not require a password, you can omit the -u and -p options: mysqldump database_name > database_name.sql Backup Multiple MySQL Databases # Depending on the database size, the process can take some time. After successful authentication, the dump process will start. You will be prompted to enter the root password. The most common use case of the mysqldump tool is to backup a single database.įor example, to create a backup of the database named database_name using the user root and save it to a file named database_name.sql you would run the following command: mysqldump -u root -p database_name > database_name.sql ![]() To use the mysqldump command the MySQL server must be accessible and running. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |