mysql导入脚本mysql import script

- 此内容更新于:2014-12-30
主题:

原文:

Is it possible to import csv data into mysql and automatically create the column names, as in can I create just the table, or must I create the table names as well?

Is it possible to check for duplicate entries upon importing? I have an identifier field, but dont know how to make it so it will not be imported twice.

How would you import a jpeg file on a website into a field? Assume the website has been stored locally, and has the same filename as an identifer with ".jpeg" added on to the end.

解决方案:
第一年说你必须处理表创建你自己,但作为导入csv而言你应该看看INFILE加载数据 重复的条目不会成为一个问题如果你有设置主键表。 jpeg的问题似乎是一个完全不同的问题(除非csv)中的数据
原文:

As tante said you'll have to handle the table creation yourself, but as far as importing csv is concerned you should have a look at LOAD DATA INFILE

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[CHARACTER SET charset_name]
[{FIELDS | COLUMNS}
    [TERMINATED BY 'string']
    [[OPTIONALLY] ENCLOSED BY 'char']
    [ESCAPED BY 'char']
]
[LINES
    [STARTING BY 'string']
    [TERMINATED BY 'string']
]
[IGNORE number LINES]
[(col_name_or_user_var,...)]
[SET col_name = expr,...]

Duplicate entries won't be a problem if you have set primary keys on your table.

The jpeg question seems like a completely different issue (unless the data is in your csv)

解决方案:
当然,但你可能要自己写几行代码,它可以用很少的代码。然后检查重复很容易,你可以在插入你的小脚本。 您可以存储文件的组合两个字段,一个Varchar名称和文件内容的一个blob。
原文:

Sure, but you'll probably have to write a few lines of code yourself, it can be done with very little code. Checking for duplicates is quite easy then, you can do that before inserting in your little script.

You could store the file as a combination of two fields, one Varchar for the name and a blob for the file contents.

解决方案:
没有 你可以添加一个独一无二的 约束——它真的取决于 你想做如果重复 发现 不使用mysql——使用一个 脚本语言的图像 然后插入数据的URL
原文:
  1. No
  2. You could add a unique constraint - it really depends what you want to do if a duplicate is found
  3. Not using mysql - use a scripting language to pull the image data from the URL then insert that
解决方案:
看起来答案你至少覆盖了前两项。为Jpeg格式的问题,看一看一个文件存储在一个数据库与文件系统?。
原文:

Looks like the answers you got covers at least the first two items. For the Jpeg question, take a look at Storing a file in a database as opposed to the file system?.