How to import SQL in MySQL?
There are several ways to import a SQL file into MySQL:
- To import using the MySQL command line tool: In the command line interface, use the following command to import the SQL file:
mysql -u 用户名 -p 数据库名 < 文件路径
Your MySQL username, database name and file path to the SQL file are required for the import process. Once you enter the command, you will be prompted to input your password. Hit enter to start the import.
- Import using MySQL’s graphical interface tool: Many MySQL graphical interface tools (such as phpMyAdmin, Navicat, etc.) offer import functionality, where you simply select the SQL file you want to import and execute the import operation.
- To import data files using the LOAD DATA command in MySQL, instead of SQL scripts, you can utilize the following command:
LOAD DATA INFILE '文件路径' INTO TABLE 表名;
The file path refers to the path of the data file, and the table name is the name of the target table for importing data. Before using the LOAD DATA command to import the data file, make sure that the MySQL server has enabled the local-infile option.
Regardless of which method you choose, you need to make sure that the imported SQL file is valid and that the structure of the database matches the imported SQL file.