MySQL Import File / Database Command

MySQL Import File / Database Command

To import a file or database into MySQL, you can use the mysql command-line utility. This utility allows you to connect to the MySQL server and run SQL statements or scripts to import data into the database.

To import a file or database into MySQL, follow these steps:

  1. Connect to the MySQL server using the mysql utility. You can use the mysql utility to connect to the MySQL server as the root user or another user with the appropriate privileges. For example:
re‮ ref‬to:lautturi.com
mysql -u root -p

Enter the password for the user account when prompted.

  1. Select the database where you want to import the data. You can use the USE command to select the database:
mysql> USE database_name;

Replace database_name with the name of the database where you want to import the data.

  1. Import the file or database using the mysql utility. You can use the following syntax to import a file or database into MySQL:
mysql> SOURCE file_name.sql;

Replace file_name.sql with the name of the file you want to import. This file can contain SQL statements or scripts to create tables, insert data, and perform other operations on the database.

  1. Disconnect from the MySQL server. Once you have finished importing the data into the database, you can disconnect from the MySQL server by typing exit at the MySQL prompt:
mysql> exit

Alternatively, you can use the mysql utility with the -e option to import a file or database directly from the command line, without connecting to the MySQL server:

mysql -u root -p database_name < file_name.sql

This will import the file or database into the specified database without the need to connect to the MySQL server.

If you are importing a large file or database, it may take some time to complete the import process. You can use the SHOW PROCESSLIST command to check the status of the import operation.

Created Time:2017-10-30 10:17:51  Author:lautturi