Import CSV file into MySQL using phpMyAdmin(使用 phpMyAdmin 将 CSV 文件导入 MySQL)
问题描述
我搜索并阅读了许多关于使用 phpMyAdmin 2.8.0.1 将 CSV 文件导入 MySQL 数据库的帖子/文章,它们听起来很简单,但实际上并非如此.我所做的一切都无法正常工作.
I have searched and read many posts/articles regarding importing a CSV file into a MySQL database using phpMyAdmin 2.8.0.1 and they make it sound so simple, in actually it is not. Nothing I do works correctly.
我有一个包含 2 列的表,均定义为 NOT NULL.主索引配置为使用两列.我有很多 CSV 文件要导入,但我首先从小的文件开始.这是我的 CSV 数据文件示例:
I have a table with 2 columns, both defined as NOT NULL. The primary index is configured to use both columns. I have many CSV files to import but I'm starting with the small ones first. Here is a sample of my CSV data file:
type description
T Antarctic Territory
T Dependency
T Independent State
T Proto Dependency
T Proto Independent State
只有 17 行要导入,但通常我会插入 0 行,有时我会插入 1 行,但格式错误.我的意思是第 1 列是空白的,第 2 列包含两列的数据,顺序错误.这是我的导入尝试生成的 SQL:
There are only 17 rows to import but usually I get 0 rows inserted and sometimes I get 1 row inserted but it is in the wrong format. What I mean is that column 1 is blank and column 2 contains the data of both columns, in the wrong order. This is the SQL generated by my import attempt:
LOAD DATA LOCAL INFILE '/var/php_sessions/uploads/phpiptDPV' REPLACE INTO TABLE `country_types`
FIELDS TERMINATED BY ' '
LINES TERMINATED BY '
'
IGNORE 1
LINES (
`type` ,
`description`
)# MySQL returned an empty result set (i.e. zero rows).
谁能看出我哪里出错了?我花了几天时间研究和尝试不同的东西,但我准备放弃 phpMyAdmin.
Can anyone see where I'm going wrong? I've spent a few days researching and trying different things but I'm ready to throw out phpMyAdmin.
推荐答案
问题在于 LOCAL.在这种情况下,本地"有两个概念.您可能是说 CSV 文件位于您运行浏览器访问 phpMyAdmin 的工作站上.
The problem is with LOCAL. There are two concepts of "local" in this case. You probably mean that the CSV file is on the workstation where you are running your browser accessing phpMyAdmin.
但是 LOAD DATA LOCAL INFILE 语句正在运行 phpMyAdmin 的 Web 服务器上运行.所以它正在寻找网络服务器上的文件.当我尝试这个时,我得到了 phpMyAdmin 的这个错误输出:
But the LOAD DATA LOCAL INFILE statement is running on the web server where phpMyAdmin is running. So it's looking for the file on the web server. When I tried this I got this error output by phpMyAdmin:
#7890 - Can't find file '/Users/billkarwin/t.csv'.
您可以尝试使用 phpMyAdmin 的导入功能.
You can try using phpMyAdmin's Import feature.
- 选择您的餐桌.
- 点击导入标签.
- 点击选择文件按钮浏览到您的本地 csv 文件.
- 为格式选择CSV using LOAD DATA".
- 选择其他格式特定选项.
- 点击开始.
- Select your table.
- Click the Import tab.
- Click the Choose file button to browse to your local csv file.
- Select the 'CSV using LOAD DATA' for Format.
- Choose other Format-Specific Options.
- Click Go.
这篇关于使用 phpMyAdmin 将 CSV 文件导入 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 phpMyAdmin 将 CSV 文件导入 MySQL
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
