I have a table in database on the remote server. I want to populate the data into the that table from the local machine. I have the csv file in the local machine which has data that needs to be uploaded data into the table of remote server.
Please suggest me how can do it through mysqlimport and from where should I execute.
Thanks in advance.
Use LOAD DATA to solve this problem. Find example below:
LOAD DATA LOCAL INFILE 'filename'
INTO TABLE `tablename`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n' (`column_name`)
Related
I am trying to insert data from text file into MySQL using LOAD DATA LOCAL INFILE command.
When I hit this command in MySQL window I get the total number of records inserted.
LOAD DATA LOCAL INFILE 'filepath' INTO TABLE tablename FIELDS TERMINATED BY '\t';
However, when I pass the same command using ruby, I see the less data is getting inserted.
connect.query("LOAD DATA LOCAL INFILE 'filepath' INTO TABLE tablename FIELDS TERMINATED BY '\\t';")
I have verified by printing the above query and it is the same.
I am using MySQL Workbench 6.3 version 6.3.10 build 12092614
If 'filepath' is a variable, is will not be expanded. Try this:
connect.query("LOAD DATA LOCAL INFILE '#{filepath}' INTO TABLE tablename FIELDS TERMINATED BY '\\t';")
If 'filepath' is a file path literal, try using an absolute path from the root. That is, if MySQL is running locally.
If this query is being submitted to a remote MySQL server, then there is no hope of it opening a local file, and you may need to rethink your import strategy completely.
I have wordpress website and have created plugin to import csv to a table. Database is in RDS. Here is the sql I have used
LOAD DATA LOCAL INFILE 'my.csv' INTO TABLE tablename CHARACTER SET UTF8 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES
(
ID,
Name
Address
)
When I run this sql in sqlyog in the same database ( database in RDS ) this works perfectly. Please note csv file used is on my windows folder and given absolute path. However when I run this sql from the plugin on the linux server (where the website is hosted), wordpress gives message saying Load data local infile is not supported. I have another website where this works fine and this is also hosted on AWS as this one and has the same configuration such as database in RDS and mysql version 5.5+ on both servers.
Am I missing anything here. Any help will be appreciated.
Thanks in advance.
Amazon RDS hosted service doesn't support the load from files. Hence it gives error.
Hence, you can't load the CSV.
Here is approach.
Convert your CSV data into insert into table(....) SQL data.
Load your data using command like below.
mysql -h <Host> -u <username> -p<Password> < Your_file.sql
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'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 ','
Is there is any way to run
LOAD DATA INFILE
command, when file exists in FTP location? For example something like this:
LOAD DATA INFILE 'USER%40WEBSITE.COM:PASSWORD#ftp.WEBSITE.COM/FILE.csv';
REPLACE INTO TABLE mytable FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n' IGNORE 1 LINES
No, MySQL file-related functions can only access files on the database server or the client, but not other machines (unless you've set up a network file system mount, to make the remote machine appear to be local).