Detailed usage of mysqldump

mysqldump is a command-line tool for backing up and restoring MySQL databases, which provides a wealth of options and features. The following is a detailed explanation of the usage of mysqldump:

  1. Backup the entire database:

    • Run the following command to back up the entire database and save the result to a file:

      mysqldump -u <用户名> -p <数据库名> > <输出文件名>.sql
    • Replace  <用户名>with the user name of the MySQL database, <数据库名>the name of the database to be backed up, and <输出文件名>the file name for saving the backup result.
    • After executing the command, you will be prompted to enter the password, and the backup will start after entering the password.
  2. Backup specified table:

    • To backup only specified tables, you can use  --tablesoption:

      mysqldump -u <用户名> -p <数据库名> --tables <表名1> <表名2> ... > <输出文件名>.sql
    • Will be  <表名1> <表名2> ...replaced with a list of table names to backup.
  3. Backup structure without data:

    • To back up only the database structure and not the data, you can use  --no-datathe option:

      mysqldump -u <用户名> -p <数据库名> --no-data > <输出文件名>.sql
  4. Backup data without structure:

    • To back up only the database data without the structure, you can use  --no-create-infothe option:

      mysqldump -u <用户名> -p <数据库名> --no-create-info > <输出文件名>.sql
  5. Restore the database:

    • To restore a database backed up from a backup file, the following command can be used:

      mysql -u <用户名> -p <数据库名> < <备份文件名>.sql
    • Replace  <备份文件名>with the actual backup filename.

Please note that when executing the mysqldump and mysql commands, <用户名>and  <数据库名>are mandatory items, and -pthere is no need for a space after the option. During the backup process, you will be prompted to enter a password, and the backup or recovery will start after entering the password. Hope this information helps you!

Guess you like

Origin blog.csdn.net/tiansyun/article/details/132114840