mysqlimport 导入数据到MySQL

非知不说 2011-11-08 04:28:12
请教:
如何用mysqlimport将.csv、和.txt格式的数据导入到MySql数据表中??
可以举个例子看下吗??
谢谢~~
...全文
178 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2011-11-08
  • 打赏
  • 举报
回复
[Quote]问个很傻的问题、如果导入.sql文件,.sql文件中的内容是什么样式的啊?[/Quote]普通的SQL语句。
非知不说 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 nicenight 的回复:]

SQL code
C:\>mysqlimport --help
mysqlimport Ver 3.4 Distrib 4.0.16, for Win95/Win98 (i32)
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLU……
[/Quote]
问个很傻的问题、如果导入.sql文件,.sql文件中的内容是什么样式的啊?
nicenight 2011-11-08
  • 打赏
  • 举报
回复
C:\>mysqlimport --help
mysqlimport Ver 3.4 Distrib 4.0.16, for Win95/Win98 (i32)
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Loads tables from text files in various formats. The base name of the
text file must be the name of the table that should be used.
If one uses sockets to connect to the MySQL server, the server will open and
read the text file directly. In other cases the client will open the text
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.

Usage: mysqlimport [OPTIONS] database textfile...
Default options are read from the following files in the given order:
C:\WINDOWS\my.ini C:\my.cnf
The following groups are read: mysqlimport client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit
--no-defaults Don't read default options from any options file
--defaults-file=# Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read
--character-sets-dir=name
Directory where character sets are
--default-character-set=name
Set the default character set.
-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.
-#, --debug[=name] Output debug log. Often this is 'd:t:o,filename'
-d, --delete First delete all rows from table.
--fields-terminated-by=name
Fields in the textfile are terminated by ...
--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 ...
--fields-escaped-by=name
Fields in the i.file are escaped by ...
-f, --force Continue even if we get an sql-error.
-?, --help Displays this help and exits.
-h, --host=name Connect to host.
-i, --ignore If duplicate unique key was found, keep old row.
--ignore-lines=# Ignore first n lines of data infile.
--lines-terminated-by=name
Lines in the i.file are terminated by ...
-L, --local Read all files through the client
-l, --lock-tables Lock all tables for write.
--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.
-r, --replace If duplicate unique key was found, replace old row.
-s, --silent Be more silent.
-S, --socket=name Socket file to use for connection.
-u, --user=name User for login if not current user.
-v, --verbose Print info about the various stages.
-V, --version Output version information and exit.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- -----------------------------
character-sets-dir (No default value)
default-character-set (No default value)
columns (No default value)
compress FALSE
delete FALSE
fields-terminated-by (No default value)
fields-enclosed-by (No default value)
fields-optionally-enclosed-by (No default value)
fields-escaped-by (No default value)
force FALSE
host (No default value)
ignore FALSE
ignore-lines 0
lines-terminated-by (No default value)
local FALSE
lock-tables FALSE
low-priority FALSE
port 3306
replace FALSE
silent FALSE
socket (No default value)
user (No default value)
verbose FALSE


需要注意的是文件名应该是如下的格式:“将要导入的表名.xxxxx”

还有就是如下几个参数用于对文件格式做区分:
--fields-enclosed- by= char
指定文本文件中数据的记录时以什么括起的, 很多情况下
数据以双引号括起。 默认的情况下数据是没有被字符括起的。
--fields-terminated- by=char
指定各个数据的值之间的分隔符,在句号分隔的文件中,
分隔符是句号。您可以用此选项指定数据之间的分隔符。
默认的分隔符是跳格符(Tab)
--lines-terminated- by=str
此选项指定文本文件中行与行之间数据的分隔字符串
或者字符。 默认的情况下mysqlimport以newline为行分隔符。
您可以选择用一个字符串来替代一个单个的字符:
一个新行或者一个回车。
非知不说 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 orchidcat 的回复:]

mysql 没弄过,简易LZ到相应版块询问。

想必也跟ms sql 类似。 openrowset 之类的吧。
[/Quote]
去哪个版块啊??我是刚加入CSDN的、谢谢~~
Mr_Nice 2011-11-08
  • 打赏
  • 举报
回复
mysql 没弄过,简易LZ到相应版块询问。

想必也跟ms sql 类似。 openrowset 之类的吧。

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧