Home >Database >Mysql Tutorial >How do I import a database into MySQL from the terminal?
Importing a Database with MySQL from the Terminal
Importing a database into MySQL using the terminal can provide a convenient way to manage data. To execute this task effectively, follow the steps outlined below:
Using the command line, you can access the MySQL prompt. The syntax for doing so is:
mysql -u username -p database_name
Enter your username, password, and the target database name in place of the placeholders.
Once connected to the database, you can import the desired data file using the following command:
< filename.sql
You can also provide the absolute path of the SQL file in the command.
For example:
mysql -u root -p wp_users < wp_users.sql
Alternatively, if you wish to avoid prompting for a password, you can include it directly in the command:
mysql -u root -pPassword123 wp_users < wp_users.sql
Please refer to the official MySQL documentation for further details.
Note: If using Windows, navigate to the MySQL/bin directory in the CMD using the "cd" (change directory) command before executing the above commands.
The above is the detailed content of How do I import a database into MySQL from the terminal?. For more information, please follow other related articles on the PHP Chinese website!