简体   繁体   中英

How do I create a script to run MySQL command line?

I'm trying to import about 20 .csv files into MySQL and I'm fed up with doing it via phpmyadmin's import gui.

Is there a way to do this by batch without typing on the command line? ie a script that will run when double clicked (Windows). What I want is:

  1. I have files like porsche.csv, ferrari.csv etc
  2. I want to import each of these into tables with the same name (ie porsche, ferrari)
  3. Empty the table before importing the text file (using delete flag). How does it handle new fields?
  4. Ignore first line (header).

From what I've gathered so far: we use mysqlimport : http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html

I'll try to fiddle around with the options and see if I can get something working.

On Windows, the easiest way is to use a batch script.

Read the documentation on available options.

The batch script would look something like:

@echo off
cd C:\Program Files\MySQL\MySQL Workbench 5.2 CE\

mysqlimport ...

Other related questions:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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