Import issue with MySQL Workbench - mysql

I am trying to import a .csv (or .txt it doesn't matter) with MySQL Workbench and I am actually using the following command :
LOAD DATA LOCAL INFILE '/path/to/your/csv/file/model.csv' INTO TABLE test.dummy FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
My .csv file is placed in the mysql/data folder of the server where my database is placed (on localhost). MySQL Workbench tells me "Query interrupted".
I previously tried to put the full path but the query was running successfully without results. My database was still empty...
Thanks for your help.

Okay so... Problem solved. It just seems that MySQLWorbench accepts this request with a direct path (no errors, script executed) but doesn't refresh his table view... So my table have been fullfilled around 3 times before I restarted MySQLWorkbench to discover that my table was full.
So... Problem solved. Sorry for the time loss.

Related

mysql csv file import issue

Using MySQL on Mac OSX. When executing the following statement (from MySQl workbench), I met with the following error,
I tried to start MySQL manually using sudo /usr/local/mysql/support-files/mysql.server start without any options, but still have this error. Wondering if any solutions?
I searched some solutions and looks like on Windows there are some .ini config files, but have not found any solutions on Mac OSX. Thanks.
LOAD DATA INFILE '/Users/foo/Downloads/import.csv'
INTO TABLE tasks
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 0.0043 sec
Best is to put the file into the server's data directory before trying to load it, for security reasons. Read more about LOAD DATA in the docs, especially about the input file location. Note also: the secure-file-priv option can be set in a config file, hence manually starting the server without any additional option will not change its behavior compared to the normal start.

Issue on Using LOAD DATA INFILE in Production Server

This code is working fine for me to load a huge .csv file into ecolo-dis-tbl table in Localhost using PHPMyAdmin and Wampserver
LOAD DATA INFILE 'C:/Data/Spreatsheets/Data-Single.csv'
INTO TABLE `ecolo-dis-tbl`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Now can some one please let me know how I can address the file in production server like Godaddy? I mean instead of C:/Data/Spreatsheets/ what path should use if I load the file into the root
Using phpMyAdmin you can select the Import tab and work with the file directly from your local machine. To use the SQL code you've posted here, you'll first have to upload the file to your production database server by means of SSH, FTP, or whatever other way you put files on the server. Note that for some hosts the web server is on a different machine from the database server, so you have to make sure they go on the database server. Then just use the new path (maybe something like /home/suffii/Data-Single.csv) in place of C:/Data/Spreatsheets/Data-Single.csv.

I have the following error mysql error #2000

I get the error message. I am using phpAdmin
2000 - Can't find file 'c:/tmp/userlist.csv'.
LOAD DATA LOCAL INFILE 'c:/tmp/userlist.csv'
INTO TABLE users2
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n';
I have googled and that error seems to be a lot of other things too.
It does exist as i have just pasted into windows and it opens the file.
With LOAD DATA LOCAL the file is read locally and it needs to be accessible by the client. You mentioned you are using phpMyAdmin (a MySQL client), so the file needs to be accessible from wherever phpMyAdmin is running from.
If phpMyAdmin isn't installed on your computer, then you need to upload the file to the server where it's located and change the file path accordingly.
Another solution would be to install a MySQL client on your computer to run the query, so it can read the file locally. I recommend MySQL Workbench.
The only thing I had to do in the end was press IMPORT inside phpMyadmin. It would have been nicer if somebody had told me that instead of mucking around for two days trying to import a csv via sqls.

Load Data In file MySQL MacOS

I'm trying to load data from a CSV using MySQL, but I'm getting Error code 29 (file not found). I'm using mac osx, but when I run the following query
LOAD DATA INFILE '/workspace/SQL_Test/src/values.csv'
INTO TABLE queryid_vs_column
COLUMNS TERMINATED BY ','
MySQL tries to look in 'C:/workspace/SQL_Test/src/values.csv'. I haven't found anyone else with similar issues, has anyone encountered something like this? I'm not sure why MySQL thinks I'm running a windows machine.
Thanks.
If you don't use the LOCAL modifier, it accesses the file on the server. Change your query to:
LOAD DATA LOCAL INFILE '/workspace/SQL_Test/src/values.csv'
INTO TABLE queryid_vs_column
COLUMNS TERMINATED BY ','

How to import a csv file into MySQL workbench?

I have a CSV file. It contain 1.4 million rows of data, so I am not able to open that csv file in Excel because its limit is about 1 million rows.
Therefore, I want to import this file in MySQL workbench. This csv file contains columns like
"Service Area Code","Phone Numbers","Preferences","Opstype","Phone Type"
I am trying to create a table in MySQL workbench named as "dummy" containing columns like
ServiceAreaCodes,PhoneNumbers,Preferences,Opstyp,PhoneTyp.
The CSV file is named model.csv. My code in workbench is like this:
LOAD DATA LOCAL INFILE 'model.csv' INTO TABLE test.dummy FIELDS TERMINATED BY ',' lines terminated by '\n';
but I am getting an error like model.CSV file not found
I guess you're missing the ENCLOSED BY clause
LOAD DATA LOCAL INFILE '/path/to/your/csv/file/model.csv'
INTO TABLE test.dummy FIELDS TERMINATED BY ','
ENCLOSED BY '"' LINES TERMINATED BY '\n';
And specify the csv file full path
Load Data Infile - MySQL documentation
In case you have smaller data set, a way to achieve it by GUI is:
Open a query window
SELECT * FROM [table_name]
Select Import from the menu bar
Press Apply on the bottom right below the Result Grid
Reference:
http://www.youtube.com/watch?v=tnhJa_zYNVY
In the navigator under SCHEMAS, right click your schema/database and select "Table Data Import Wizard"
Works for mac too.
You can use MySQL Table Data Import Wizard
At the moment it is not possible to import a CSV (using MySQL Workbench) in all platforms, nor is advised if said file does not reside in the same host as the MySQL server host.
However, you can use mysqlimport.
Example:
mysqlimport --local --compress --user=username --password --host=hostname \
--fields-terminated-by=',' Acme sales.part_*
In this example mysqlimport is instructed to load all of the files named "sales" with an extension starting with "part_". This is a convenient way to load all of the files created in the "split" example. Use the --compress option to minimize network traffic. The --fields-terminated-by=',' option is used for CSV files and the --local option specifies that the incoming data is located on the client. Without the --local option, MySQL will look for the data on the database host, so always specify the --local option.
There is useful information on the subject in AWS RDS documentation.
If the server resides on a remote machine, make sure the file in in the remote machine and not in your local machine.
If the file is in the same machine where the mysql server is, make sure the mysql user has permissions to read/write the file, or copy teh file into the mysql schema directory:
In my case in ubuntu it was: /var/lib/mysql/db_myschema/myfile.csv
Also, not relative to this problem, but if you have problems with the new lines, use sublimeTEXT to change the line endings to WINDOWS format, save the file and retry.
It seems a little tricky since it really had bothered me for a long time.
You just need to open the table (right click the "Select Rows- Limit 10000") and you will open a new window. In this new window, you will find "import icon".
https://www.convertcsv.com/csv-to-sql.htm
This helped me a lot. You upload your excel (or .csv) file and it would give you an .sql file with SQL statements which you can execute - even in the terminal on Linux.