How can we transfer information between MySQL and data files through command line?

MySQLMySQLi Database

Transferring the information between MySQL and data files mean importing data from data files into our database or exporting data from our database into files. MySQL is having two commands that can be used to import or export data between MySQL and data files through the command line −

mysqlimport 

Actually, mysqlimport command reads a spread of data formats, including comma-and tab-delimited, and inserts the information into a database. In other words, we can say that it provides a command-line interface for importing the data i.e. command-line interface to the LOAD DATA INFILE statement. Its syntax would be as follows −

Syntax

Mysqlimport [options] database_name filename1 filename2 …

Here, filenames must correspond to the tables into which data will be imported.

 mysqldump

Basically, mysqldump is a client program that can be used to dump a database or a collection of databases for backup or transfer to another database server. It can export tables as tab-delimited data files or produce SQL-format dump files that contain CREATE TABLE and INSERT statements for re-creating the dumped files. Its syntax would be as follows −

Syntax

Mysqldump –tab=dir_name options db_name tbl_name …

As we are specifying –tab=dir_name means mysqldump export the tables as tab-delimited data files and issue SELECT … INTO OUTFILE statement to tell MySQL server to write each dumped table as a tab-delimited text file in the dir_name directory.

Both the above-described commands are similar in the sense that they are related to the transfer of data either from the data file to database or from the database to the data file.

raja
Published on 20-Feb-2018 09:58:57
Advertisements