How To Export and Import a .SQL File From Command Line With Options? Last Updated : 02 Oct, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Structured Query Language is a computer language that we use to interact with a relational database.SQL is a tool for organizing, managing, and retrieving archived data from a computer database. In this article , we will learn to export and import .SQL files with command line options. Export:You can export the database along with its structure into .SQL file using a command line tool called mysqldump as follows , Syntax : mysqldump -h localhost -u username -p database > filename.sql where, -h / --host : host address to connect-u / --user : username of the account in the server-p / --password : to get the password promptdatabase : name of the database to importfilename.sql : the output fileFor example, the complete command looks something like the below and creates a file by the name filename.sql. Query: mysqldump --column-statistics=0 -h localhost -u root -p --events --triggers --routines company > filename.sqlOutput : This has created the sql file with the given name. Import :You can import the database along with its structure into .SQL file using a command line tool called mysql as follows , Syntax : mysql -h localhost -u username -p database < input.sql where, -h / --host : host address to connect-u / --user : username of the account in the server-p / --password : to get the password promptdatabase : name of the database to importinput.sql : the input .SQL fileFor example, here we will import the filename.sql that was exported above: Query: mysql -h localhost -u root -p company < filename.sqlOutput : Now you can find the database company on the server. Comment More infoAdvertise with us Next Article How to Import Data From a CSV File in MySQL? N nikhilkalburgi Follow Improve Article Tags : SQL SQL-Query Similar Reads How to import and export data using CSV files in PostgreSQL In this article, we are going to see how to import and export data using CSV file in PostgreSQL, the data in CSV files can be easily imported and exported using PostgreSQL. To create a CSV file, open any text editor (notepad, vim, atom). Write the column names in the first line. Add row values separ 3 min read How to Import and Export SQL Server Data to an Excel File? SQL Server is very popular in Relational Database and it is used across many software industries. Portability of data is a much-required feature of any database. i.e. Database should support features like exporting database data to Excel/CSV/JSON and also should import data from them. In this articl 3 min read How to Import Data From a CSV File in MySQL? Importing data from a CSV (Comma-Separated Values) file into a MySQL database is a common task for data migration and loading purposes. CSV files are widely used for storing and exchanging tabular data. However, we cannot run SQL queries on such CSV data so we must convert it to structured tables. I 10 min read How to Export SQL Server Data to a Text File Format? Exporting SQL Server data to a text file is a common task that is used in data migration, data sharing, etc. SQL Server provides several methods to export data to a text file format, including using the SQL Server Management Studio (SSMS), the SQL Server Command Line Tool (sqlcmd), and the SQL Serve 4 min read How to Export a Table Data to a PDF File in SQL? SQL Server is a versatile database. It is used across many industries. We can use AZURE data studio as well as SQL Server Management Studio for doing various operations (DDL, DML, Stored Procedure, Trigger preparations) etc., SQL Server supports the portability of data using the EXPORT option. By de 2 min read How to Export Data From SQL Server to Flat File in SSIS? In this article, we will learn how to Export Data From SQL Server To Flat File in SSIS. For this, we are going to create a package to select the data from the SQL server database and export SQL Server table data to the Flat File in the local drive. Prerequisites:Make sure Visual Studio 2019 is insta 3 min read Like