To import a database using MySQL, follow these steps:
- Open a terminal or command prompt.
- Navigate to the directory where the database dump file (usually with a .sql extension) is located.
- Ensure that MySQL is installed and running on your system.
- Run the following command to import the database:
mysql -u username -p database_name < dump_file.sql
Replace username with your MySQL username, database_name with the name of the database you want to import the data into, and dump_file.sql with the actual name of your dump file.
- When prompted, enter your MySQL password. Note that while typing the password, it won't be visible on the screen.
- Wait for the import process to complete. Depending on the size of the database, this may take some time.
To extract (or export) a database using MySQL, use the following command:
mysqldump -u username -p database_name > dump_file.sql
Replace username with your MySQL username, database_name with the name of the database you want to export, and dump_file.sql with the desired name for the dump file.
When prompted, enter your MySQL password. The command will create a new file named dump_file.sql in the current directory, containing the SQL statements necessary to recreate the database structure and data.
Remember to replace username, database_name, and dump_file.sql with the appropriate values based on your setup.