Backup mysql database on windows

Option 1: Use the mysqldump tool that comes with mysql.

The script file backup.bat is as follows:

 

set  "YMD=%date:~,4%%date:~5,2%%date:~8,2%"
cd    /d   C:\Program Files\MySQL\MySQL Server 5.7\bin
mysqldump  --no-defaults    -uroot    -p"501501"    sdxs    >  E:/databaseBackupData/sdxs/sdxs_%YMD%.sql

The explanation is as follows:

      1. Set "YMD=%date:~,4%%date:~5,2%%date:~8,2%" means that the variable YMD is assigned the year, month, and day when the script is executed, such as 20180505.

      2. cd    /d    C:\Program Files\MySQL\MySQL Server 5.7\bin means switch the cmd directory to C:\Program Files\MySQL\MySQL Server 5.7\bin. Note that /d must be added. Otherwise it fails.

      3、mysqldump  --no-defaults    -uroot    -p"501501"    sdxs     >  E:/databaseBackupData/sdxs/sdxs_%YMD%.sql       

         Indicates the execution of the mysqldump command . The role of --no-defaults is mainly to solve the --no-beep error that occurs when the command is executed. That is the error as shown below.

     4. The complete mysqldump command is expressed as follows:

mysqldump --no-defaults --user=root --password=123456 --host=127.0.0.1 --port=3306  google >d:/databaseBackup/my.sqlml

        If the --no-data option is added, only the structure will be backed up and the data will not be backed up.

       --host=127.0.0.1 is used to specify the ip address where the mysql database is located, which is specified here as the local ip  . Therefore, it can be backed up remotely and off -site . This option is used to specify which machine to back up the mysql database.

       --port=3306 is used to specify the port used by mysql to specify the database service, which is specified as port 3306 here  .

       --databases database A, database B, database C, etc., is used to specify which databases of the specified mysql server are backed up. If you back up all tables of all databases on this mysql server, use the --all-databases option

       --user="igoodful" is used to specify the username of the database, where the specified username is igoodful.

       --password="123456" Indicates the password of the database user. Here, the password specified for the igoodful user is 123456.

       --comments="fine" Indicates adding comments to the backup file.

       --default-character-set =utf8 Indicates the default character set used by this database.

       --events means that the events of the database will also be backed up, and events will not be backed up by default.

       --password="123456" Indicates the password of the database user. Here, the password specified for the igoodful user is 123456.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325330517&siteId=291194637