How to execute an sql file in Mysql?
There are multiple methods to run an SQL file in MySQL, but two common ones are listed below:
Option 1: Utilize the MySQL command line tool.
- Open either the command line terminal or the MySQL command line tool.
- Login to the MySQL database using the following command:
mysql -u 用户名 -p 密码
Please replace “username” and “password” with the actual database username and password.
- After accessing the MySQL database, run the SQL file using the following command:
source /path/to/sql/file.sql
Please make sure to replace “/path/to/sql/file.sql” with the actual path to the SQL file.
Option 2: Utilize MySQL Workbench.
- Open MySQL Workbench and connect to the MySQL database.
- Select the database in the left panel where you want to run the SQL file.
- Select “Server” from the top menu bar and then choose “Data Import”.
- In the pop-up dialog box, choose the option “Import from Self-Contained File” and click on the “Browse” button to select the SQL file you want to import.
- Click the “Start Import” button to begin importing the SQL file.
After the import is completed, you will be able to see the imported data table and data in the MySQL database.