📜  mysqlimport - SQL (1)

📅  最后修改于: 2023-12-03 15:33:04.350000             🧑  作者: Mango

Introduction to mysqlimport - SQL

mysqlimport is a command-line tool in MySQL that allows programmers to import CSV and TSV files into MySQL databases. This tool simplifies data loading into the MySQL database and can be used with minimal coding effort.

Syntax
mysqlimport [OPTIONS] database textfile ...
  • OPTIONS: Used to specify the operation options and connection parameters.
  • database: Specifies the MySQL database to use.
  • textfile: Specifies the path and name of the file to import.
Options

Following are commonly used options for mysqlimport:

  • -u: Specifies the username to use while connecting to the MySQL server.
  • -p: Asks for the password for the MySQL server.
  • -h: Specifies the MySQL server host address.
  • -c: Specifies the columns to import. Useful for skipping unwanted columns.
  • -t: Specifies the field delimiter character- a tab by default.
Examples
Import data from a CSV file
mysqlimport --fields-terminated-by=, --local -u root -p mydb /path/to/data/file.csv

This command imports data from a CSV file located at /path/to/data/file.csv into a table within the MySQL database "mydb".

Import data from a TSV file
mysqlimport --fields-terminated-by='       ' --local -u root -p mydb /path/to/data/file.tsv

This command imports data from a TSV file located at /path/to/data/file.tsv into a table within the MySQL database "mydb".

Conclusion

mysqlimport is an essential tool for developers who need to populate databases with data from CSV and TSV files. It provides a simple and efficient way to load data into MySQL databases with minimal coding effort.