How to export an SQL file from MySQL?
There are two methods to export a MySQL database to an SQL file:
Option 1: Utilize command line tools.
- Open Command Prompt (Windows) or Terminal (Mac/Linux).
- Enter the following command:
mysqldump -u [用户名] -p [数据库名] > [文件名].sql
Replace [username] with your MySQL username, [databasename] with the name of the database you want to export, and [filename] with the name of the exported SQL file.
3. Press Enter to execute the command, and enter your MySQL password when prompted.
4. The exported SQL file will be saved in the current directory.
Option 2: Utilize MySQL Workbench.
- Open MySQL Workbench and connect to the database you want to export.
- From the navigation panel, choose the “Server” menu, then select “Data Export.”
- Select the tables to be exported in the “Tables to Export” tab of the “Data Export” window.
- Choose the file format (SQL format) and saving location in the “Export Options” tab.
- Click the “Start Export” button to begin exporting, the exported SQL file will be saved in the specified location.
Regardless of the method used, the exported SQL file can be used to import data into another MySQL database or as a backup file.