How to use mysqldump for MySQL.
Mysqldump is a command-line tool that comes bundled with MySQL, used for backing up database data and structure. It can export table structure and data from a database into an SQL script file, allowing for easy re-importing when needed.
Here are some common options and usage examples for mysqldump:
- Back up the entire database.
- Backup the database with the username, password, and database name specified using mysqldump command. Save the backup to a file named “backup_filename.sql”.
- Back up the specified table:
- Backup the databases with specific tables using the username and password specified in the command.
- Back up the entire database, including triggers and stored procedures.
- Create a backup of a database with routines and triggers using mysqldump, specifying the username, password, and database name. Save the backup to a SQL file.
- Backup the database structure, excluding data.
- Backup the database named “database_name” excluding the data, using the username “username” and password “password”, into a file named “backup_file.sql” using the command mysqldump.
- Backup database data, excluding the structure.
- Create a backup of a database named “数据库名” without including the create table statements, using the username “用户名” and password “密码” and save it to a file named “备份文件名.sql” using mysqldump.
- Compress backup files when backing up the database.
- Backup the database by using the mysqldump command with the specified username, password, and database name, then compress the backup file using gzip.
- Restore database:
- mysql with username, password, and database name to import backup file backupfilename.sql.
Please replace the username, password, database name, table name, backup filename, etc. in the above command according to the actual situation.
In addition to the options mentioned above, mysqldump also offers many other options, such as only backing up specific data rows or ignoring errors during the backup process. You can view detailed explanations of all options by using the mysqldump –help command.