MYSQL入门学习之二十:MYSQLIMPORT命令参数详解


        MySQLimport位于MySQL/bin目录中,是MySQL的一个载入(或者说导入)数据的一个非常有效的命令行工具。
        使用mysqlimport -?命令,可以查看mysqlimport的具体参数及详细说明。下表是一些常见的选项:
-c, --columns=nameUse 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, --compressUse compression in server/client protocol.压缩在客户端和服务器之间发送的所有信息(如果二者均支持压缩)
-d, --deleteFirst delete all rows from table.新数据导入数据表中之前删除数据数据表中的所有信息
--fields-terminated-by=nameFields in the textfile are terminated by …指定数据之间的分隔符。默认的分隔符是跳格符(Tab)
--fields-enclosed-by=nameFields in the importfile are enclosed by ...指定文本文件中数据的记录是以什么括起的, 很多情况下数据以双引号括起。 默认的情况下数据是没有被字符括起的
--fields-optionally-enclosed-by=nameFields in the i.file are opt. enclosed by …字段包括符,只用在CHAR和VERCHAR字段上
--fields-escaped-by=nameFields in the i.file are escaped by ...转义字符
-f, --forceContinue even if we get an sql-error.不管是否遇到错误,MySQLimport将强制继续插入数据
-?, --helpDisplays this help and exits.显示帮助消息并退出
-h, --host=nameConnect to host.将数据导入给定主机上的MySQL服务器。默认主机是localhost
-i, --ignoreIf duplicate unique key was found, keep old row.跳过或者忽略那些有相同唯一关键字的行, 导入文件中的数据将被忽略
--ignore-lines=#Ignore first n lines of data infile.忽视数据文件的前n行
--lines-terminated-by=nameLines in the i.file are terminated by ...行记录分隔符。 默认的情况下MySQLimport以newline为行分隔符
-L, --localRead all files through the client.从本地客户端读入输入文件
-l, --lock-tablesLock all tables for write (this disables threads).数据被插入之前锁住表,防止在更新数据库时,用户的查询和更新受到影响
--low-priorityUse 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, --pipeUse 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=nameThe protocol of connection (tcp,socket,pipe,memory).连接使用的协议
-r, --replaceIf duplicate unique key was found, replace old row.与-i选项的作用相反;此选项将替代表中有相同唯一关键字的记录
--shared-memory-base-name=nameBase name of shared memory.共享内存连接名。该选项只用于Windows
-s, --silentBe more silent.沉默模式。只有出现错误时才输出
-S, --socket=nameSocket 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=nameUser for login if not current user.连接服务器时MySQL使用的用户名
-v, --verbosePrint info about the various stages.冗长模式。打印出程序操作的详细信息
-V, --versionOutput version information and exit.显示版本(version)
       
        示例:
  1. C:\Users\qxl>mysql -e "create table test.test_import(user_id int,user_name varchar(20))"  
  2. ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using passwordNO)  
  3.   
  4. C:\Users\qxl>mysql -uroot -e "create table test.test_import(user_id int,user_name varchar(20))"  
  5.   
  6. C:\Users\qxl>type h:\test_import.sql  
  7. '1','Roses'  
  8. C:\Users\qxl>mysqlimport -uroot --fields-terminated-by=, --fields-enclosed-by=' test h:\test_import.sql  
  9. test.test_import: Records: 1  Deleted: 0  Skipped: 0  Warnings: 0  
  10.   
  11. C:\Users\qxl>mysql -uroot -e "select * from test.test_import"  
  12. +---------+-----------+  
  13. | user_id | user_name |  
  14. +---------+-----------+  
  15. |       1 | Roses     |  
  16. +---------+-----------+  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值