简体   繁体   English

将CSV文件导入MySQL,而无需使用加载数据infile

[英]Import CSV file into MySQL without using load data infile

I have recently switched web hosting providers and the new provider does not allow 'load data infile' commands in MySQL. 我最近更换了Web托管提供程序,新的提供程序不允许在MySQL中“加载数据文件”命令。 However, I have many CSV files that update tables in a database weekly using that command. 但是,我有许多CSV文件,它们使用该命令每周更新数据库中的表。 What is the best way to import into MySQL without the typical load data option? 没有典型的加载数据选项,导入MySQL的最佳方法是什么? I tried mysqlimport, but that seems to fail since the data isn't in SQL format, its just standard CSV data. 我尝试了mysqlimport,但这似乎失败了,因为数据不是SQL格式,而只是标准CSV数据。 Thanks for your help. 谢谢你的帮助。

Use the following process: 使用以下过程:

  • Convert the CSV to the MySQL CSV dump format 将CSV转换为MySQL CSV转储格式
  • Upload the file to the MySQL server or to the shared hosting file system 将文件上传到MySQL服务器或共享主机文件系统
  • Use one of the following commands to import it: 使用以下命令之一将其导入:

    • mysqladmin: mysqladmin:

       mysqladmin create db1 mysql db1 < dump.csv 
    • mysql: MySQL的:

       mysql> CREATE DATABASE IF NOT EXISTS db1; mysql> USE db1; mysql> source dump.csv 

References 参考文献

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM