- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
- How to run SQL script in MySQL?
- Executing SQL Statements from a Text File on MySQL Client
- MySQL Differences from Standard SQL
- Convert timestamp coming from SQL database to String PHP?
- Database Wars: MSSQL Server, Oracle PL/SQL and MySQL
- 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
- How can we retrieve file from database using JDBC?
- Selecting random entry from MySQL Database?
- Create a database in MySQL from Java?
- Write a program in Python to read sample data from an SQL Database
- What is NoSQL (Not Only SQL database)