Added instructions to import a database in MySQL from a file.
This commit is contained in:
parent
5043963095
commit
8d2b4a9c84
60
Practical/README.md
Normal file
60
Practical/README.md
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# How to import database in MySQL
|
||||||
|
|
||||||
|
This is a guide for importing a database in MySQL using the terminal.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
- Have MySQL installed on your machine
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Guide
|
||||||
|
|
||||||
|
1. Download the database file from this repository. These database files have `.sql` extension and can be found in the Assignment folders within the [Practical folder](https://git.kska.io/DatabaseManagementSystems/src/branch/main/Practical/).
|
||||||
|
|
||||||
|
2. After downloading the file, locate it in the `Files` app. The downloaded file will mostly likely be preset in the _Downloads_ folder.
|
||||||
|
|
||||||
|
3. Right click in a empty space in the `Files` app window, and click on `Open in Terminal` (or something along those lines).
|
||||||
|
|
||||||
|
4. Now, start `mysql`
|
||||||
|
```shell
|
||||||
|
sudo mysql -u root -p
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Create an empty database & exit:
|
||||||
|
```sql
|
||||||
|
CREATE DATABASE database_name;
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
|
||||||
|
> `database_name` is the name of your database in which all the tables, data, etc. will be imported.
|
||||||
|
|
||||||
|
6. Lastly, import the database from `database.sql` file:
|
||||||
|
```shell
|
||||||
|
sudo mysql -u root -p database_name < database.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Let's consider I want to import the database for Assignment-A2. The database file is present in [Practical/Assignment-A2](https://git.kska.io/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2) folder.
|
||||||
|
|
||||||
|
1. First download the [Database_A2.sql](https://git.kska.io/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2/Database_A2.sql) file.
|
||||||
|
|
||||||
|
2. Locate the file in `Files` app, mostly likely present in the _Downloads_ folder.
|
||||||
|
|
||||||
|
3. Right click in an empty space in the **Files** app window and click **Open in Terminal**.
|
||||||
|
|
||||||
|
4. Start mysql: `sudo mysql -u root -p`
|
||||||
|
|
||||||
|
5. Create an empty database: `CREATE DATABASE Database_A2`
|
||||||
|
|
||||||
|
6. Exit from mysql: `exit`
|
||||||
|
|
||||||
|
7. Lastly, import the file: `sudo mysql -u root -p Database_A2 < Database_A2.sql`
|
||||||
|
|
||||||
|
8. That's it! Your database has been imported in MySQL.
|
||||||
|
|
||||||
|
---
|
Loading…
Reference in New Issue
Block a user