- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Run SQL file in MySQL database from terminal?
To run SQL file in database, you need to use below syntax:
mysql -u yourUserName -p yourDatabaseName < yourFileName.sql
To understand the above syntax, let us open command prompt using windows+R shortcut key.
The snapshot is as follows:
After pressing OK button, you will get a command prompt. The snapshot is as follows:
Now reach the bin directory, the snapshot is as follows:
Here is my file ‘mydb.sql’ which is located in bin directory. The snapshot and content of SQL file is as follows:
Now you can type the above syntax which I have discussed to run SQL file. The snapshot of command is as follows:
Now you can check the table ‘Instructor’ is created in database test or not.
Now switch to database test using USE command. The query is as follows:
Now check the table ‘Instructor’ is present in test database. The query is as follows:
Yes, we have Instructor table. Now we need to check the record is present or not which is inserted in the table. The query is as follows:
mysql> select *from instructor;
The following is the output:
+----+-------+ | id | Name | +----+-------+ | 1 | John | | 2 | Larry | | 3 | Sam | +----+-------+ 3 rows in set (0.00 sec)
- Related Articles
- How to run SQL script in MySQL?
- Executing SQL Statements from a Text File on MySQL Client
- Strategies For Migrating From SQL to NoSQL Database?
- Database Wars: MSSQL Server, Oracle PL/SQL and MySQL
- MySQL Differences from Standard SQL
- Convert timestamp coming from SQL database to String PHP?
- Set Database From Single User Mode to Multi User in SQL?
- Writing data from database to .csv file
- How to run .SQL script using JDBC?
- Execute MySQL query from the terminal without printing results?
- Create User SQL in SAP HANA database
- Create View SQL in SAP HANA database
- Write a program in Python to read sample data from an SQL Database
- Create a database in MySQL from Java?
- How can we retrieve file from database using JDBC?