Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert CSV file To Mysql (.sql) database file?

I am using : WampServer 2.2, Apache Version :2.2.21, PHP Version : 5.3.8, MySQL Version :5.5.16, PhpMyadmin Version: 3.4.5...

I have face Problem Of Importing CSV file-(size 13MB*), Error File is Too large... phpMyadmin allow only 2MB file size ...

So Separate files with 1.83MB file size...then also it does not work ???

And also tell me , How to automatic create table through CSV file ...?

like image 281
Nimesh Vagadiya Avatar asked Feb 19 '13 06:02

Nimesh Vagadiya


People also ask

How do I import CSV file into MySQL database?

In the Format list, select CSV. Changing format-specific options. If the csv file is delimited by a character other than a comma or if there are other specifications to the csv files, we can change it in this portion. Click Go to start importing the csv file and the data will be successfully imported into MySQL.

How do I create a .SQL file in MySQL?

If you want to create a new database for the SQL file, you can do it with the following command: mysql> CREATE DATABASE DatabaseName; To create a MySQL user and assign a new password to it, run the following command: mysql> CREATE USER 'DatabaseUser'@'localhost' IDENTIFIED BY 'password';


4 Answers

Why dont you try to import file using MySQL Console?
I think, you will not face any problem this way. You will not need to split the file into chunks. Just take care of syntax.

load data infile 'c:/filename.csv' into table tablename fields terminated by ',';

For details about syntax, refer Load Data Infile on official documentation.
For example, refer this and this.

Hope it helps!!!

like image 178
Bhavik Shah Avatar answered Sep 30 '22 17:09

Bhavik Shah


LOAD DATA INFILE 'your.csv' INTO TABLE android_dev FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;

include the csv file in your database folder,i.e., <root>\mysql\data\DATABASE_NAME

like image 23
Dheeraj Avvari Avatar answered Oct 01 '22 17:10

Dheeraj Avvari


I'd suggest you look at Data Transformer (disclaimer - I'm its developer). It can convert CSV/JSON/XML to SQL. The generated SQL contains "insert" statements for each line and a "create table" statement.

The app works offline and your data never leaves your computer.

You can get it from the Mac App Store or the Microsoft Store.

like image 40
Geo Systems Avatar answered Oct 01 '22 17:10

Geo Systems


How to automatic create table through CSV file ...?

I wrote a csv2mysql command. It scans the entier CSV file to determine appropriate column types and outputs a CREATE TABLE statement and (optionally) INSERT INTO statements for the data.

It's at https://github.com/artfulrobot/csv2mysql (you can just download the bin/csv2mysql executable (Linux) or you can run the main csv2mysql.php file if you download the source and run composer install)

like image 45
artfulrobot Avatar answered Oct 01 '22 17:10

artfulrobot