使用CSV文件更新MySQL表 [英] Update MySQL Table using CSV file

查看:434
本文介绍了使用CSV文件更新MySQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的MySQL表 employee_data 有13k行,17列。表中的数据来自CSV文件 Employees.csv 。在导入我的csv数据后,我添加了一个新的列密码(所以它不在csv文件中)密码被编辑和通过门户访问。我现在有一个更新的csv文件,我想更新我的主表与该数据,但我不想失去我的密码信息。

my Current MySQL table employee_data has 13k rows with 17 columns. The data in the table came from a CSV file Employees.csv. after importing my csv data I added a new column 'password' (so its not in the csv file) Password is edited and accessed via a web portal. I now have an updated csv file and I want to update my main table with that data but I don't want to lose my password info.

我应该将新的CSV文件导入我的数据库中的临时表,还有一些如何比较?我不知道从哪里开始,我接受建议。

Should I import my new CSV file into a temp table in my database and some how compare them? I am not sure where to start and I am open to recommendations.

我现在意识到我应该将我的密码信息保存在单独的表中。 Doh!

我想我可以创建一个php文件,比较每行基于employee_id字段,但13k行,恐怕会超时。

I guess I could created a php file that compares each row based on the employee_id field but with 13k rows I am afraid it would time out possibly.

推荐答案

我会这样做:


  • 使用<$创建临时表 c $ c> CREATE TABLE new_tbl LIKE orig_tbl; 语法

  • 使用 LOAD DATA INFILE 将CSV中的数据导入表格

  • 使用 UPDATE 使用主键/唯一列(可能 employee_id )更新主表

  • Create a temp table using CREATE TABLE new_tbl LIKE orig_tbl; syntax
  • use LOAD DATA INFILE to import the data from the CSV into the table
  • Use UPDATE to update the primary table using a primary key / unique column (perhaps employee_id)

我已经使用了包含120万行的表格和导入的CSV文件,其中包含3000万行 - 这是我所有时间使用的方法 - 比PHP中的任何东西都高效这是我的服务器端语言的选择)

I have worked with tables containing 120 million lines and imported CSV files containing 30 million lines into it - this is the method I use all of the time - much more efficient than anything in PHP (and thats my server side language of choice)

这篇关于使用CSV文件更新MySQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆