使用mysqlimport -?命令,可以查看mysqlimport的具體參數及詳細說明。下表是一些常見的選項:
-c, --columns=name | Use only these columns to import the data to. Give the column names in a comma separated list. This is same as giving columns to LOAD DATA INFILE. | 該選項採用用逗號分隔的列名作爲其值。列名的順序指示如何匹配數據文件列和表列。 |
-C, --compress | Use compression in server/client protocol. | 壓縮在客戶端和服務器之間發送的所有信息(如果二者均支持壓縮) |
-d, --delete | First delete all rows from table. | 新數據導入數據表中之前刪除數據數據表中的所有信息 |
--fields-terminated-by=name | Fields in the textfile are terminated by … | 指定數據之間的分隔符。默認的分隔符是跳格符(Tab) |
--fields-enclosed-by=name | Fields in the importfile are enclosed by ... | 指定文本文件中數據的記錄是以什麼括起的, 很多情況下數據以雙引號括起。 默認的情況下數據是沒有被字符括起的 |
--fields-optionally-enclosed-by=name | Fields in the i.file are opt. enclosed by … | 字段包括符,只用在CHAR和VERCHAR字段上 |
--fields-escaped-by=name | Fields in the i.file are escaped by ... | 轉義字符 |
-f, --force | Continue even if we get an sql-error. | 不管是否遇到錯誤,MySQLimport將強制繼續插入數據 |
-?, --help | Displays this help and exits. | 顯示幫助消息並退出 |
-h, --host=name | Connect to host. | 將數據導入給定主機上的MySQL服務器。默認主機是localhost |
-i, --ignore | If duplicate unique key was found, keep old row. | 跳過或者忽略那些有相同唯一關鍵字的行, 導入文件中的數據將被忽略 |
--ignore-lines=# | Ignore first n lines of data infile. | 忽視數據文件的前n行 |
--lines-terminated-by=name | Lines in the i.file are terminated by ... | 行記錄分隔符。 默認的情況下MySQLimport以newline爲行分隔符 |
-L, --local | Read all files through the client. | 從本地客戶端讀入輸入文件 |
-l, --lock-tables | Lock all tables for write (this disables threads). | 數據被插入之前鎖住表,防止在更新數據庫時,用戶的查詢和更新受到影響 |
--low-priority | Use LOW_PRIORITY when updating the table. | 低優先級 |
-p, --password[=name] | Password to use when connecting to server. If password is not given it's asked from the tty. | 提示輸入密碼 |
-W, --pipe | Use named pipes to connect to server. | 使用命名管道連接服務器 |
-P, --port=# | Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306). | 用於連接的TCP/IP端口號 |
--protocol=name | The protocol of connection (tcp,socket,pipe,memory). | 連接使用的協議 |
-r, --replace | If duplicate unique key was found, replace old row. | 與-i選項的作用相反;此選項將替代表中有相同唯一關鍵字的記錄 |
--shared-memory-base-name=name | Base name of shared memory. | 共享內存連接名。該選項只用於Windows |
-s, --silent | Be more silent. | 沉默模式。只有出現錯誤時才輸出 |
-S, --socket=name | Socket file to use for connection. | 當連接localhost時使用的套接字文件(爲默認主機) |
--use-threads=# | Load files in parallel. The argument is the number of threads to use for loading data. | 並行多線程導入個數 |
-u, --user=name | User for login if not current user. | 連接服務器時MySQL使用的用戶名 |
-v, --verbose | Print info about the various stages. | 冗長模式。打印出程序操作的詳細信息 |
-V, --version | Output version information and exit. | 顯示版本(version) |
示例:
shell> mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test shell> ed a 100 Max Sydow 101 Count Dracula . w imptest.txt 32 q shell> od -c imptest.txt 0000000 1 0 0 \t M a x S y d o w \n 1 0 0000020 1 \t C o u n t D r a c u l a \n 0000040 shell> mysqlimport --local test imptest.txt test.imptest: Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 shell> mysql -e 'SELECT * FROM imptest' test +------+---------------+ | id | n | +------+---------------+ | 100 | Max Sydow | | 101 | Count Dracula | +------+---------------+