Issue Using a .txt File to Populate a MySQL Database - mysql

I am learning to use MySQL Workbench and am having trouble importing data. I have created a database, a schema, and a table. The table has three columns. I have been using the following query to try to populate the table using a .txt file. The file uses new lines to separate rows and two spaces to separate columns.
LOAD DATA LOCAL INFILE 'C:\Users\Nick\Desktop\toImport.txt'
INTO TABLE schema.table
FIELDS TERMINATED BY ' '
LINES STARTING BY '\n';
Unfortunately, I keep getting the following error:
Error Code: 2. File 'C:UsersNickDesktoptoImport.txt' not found (Errcode: 2 - No such file or directory)
Any suggestions on what I am doing wrong? This is my first go at learning SQL so apologies if this is quite basic. Thanks!

As suggested in the comments, using "/" allowed the script to execute. However, using "\" did not work.
Once I removed a column from the table, all data imported perfectly.
Thanks for the help!

Related

How to export your database after you make some queries in mysql workbench?

I'm new in mysql workbench properties. so here is the situation
i have 2 tables, 'student' and 'classes'. a student can have multiple classes with student ID as the connected field. one to many relationship. i wrote some queries that connects the two table (i.e using join,...) and i want to export what i have on my queries rather than the two tables (which i got from data export wizard).
i've tried to export to csv file using codes but came across the error 1290
select teacher.student.U_id, teacher.student.U_id, teacher.student.F_name, teacher.student.L_name
teacher.classess.days,teacher.classess.mor, teacher.classess.aft
from teacher.student, teacher.classesss
where teacher.student.U_id=teacher.classess.U_id
INTO OUTFILE 'C:\Users\Eddie Vu\Downloads'
FIELDS ENCLOSED BY '"'
TERMINATED BY ';'
ESCAPED BY '"'
LINES TERMINATED BY '\r\n';
i expect the output to be store in a csv file.
please help, thank you in advance
Your command, if it worked, would create the file on the server machine. But probably that directory doesn't exist or MySQL isn't allowed to write to it or it is configured not to do so.
But I suppose you want to export to a file on the client machine.
Note the section "Export/Import" in the little toolbar above the result grid and the little button with a disk in front of a grid.
If you click that button a dialog opens that allows you to save the current result in the grid to a file.

sqlite load data infile Syntax Error

I'm working on importing a very large CSV file into SQLite. My understanding is that LOAD DATA INFILE is my best bet. I've created a table for it to reside in, and am attempting to execute the following query
LOAD DATA LOCAL INFILE 'F:/Downloads/NielsonReport.csv'
INTO TABLE neilson;
IGNORE 1 LINES
but, I get the following error:
Error while executing SQL query on database 'test': near "LOAD": syntax error
I seem to be getting an error along these lines regardless of what I'm trying to execute.
I feel like I'm missing something very basic, and would appreciate any help resolving this problem (I've been referencing this page for information so far)
When you are using SQLite, it would be a good idea to reference the SQLite documentation instead.
Anyway, SQLite itself does not have a CSV import function. But the sqlite3 command-line shell allows to import CSV files with the .import command.
Use import command like this.
.import '/Users/haseeb/Desktop/names_data.txt' Names

Replace contents of MySQL table with contents of csv file on a remote server

I'm a newbie here trying to import some data into my wordpress database (MySQL) and I wonder if any of you SQL experts out there can help?
Database type: MySQL
Table name: wp_loans
I would like to completely replace the data in table wp_loans with the contents of file xyz.csv located on a remote server, for example https://www.mystagingserver.com/xyz.csv
All existing data in the table should be replaced with the contents of the CSV file.
The 1st row of the CSV file is the table headings so can be ignored.
I'd also like to automate the script to run daily at say 01:00 in the morning if possible.
UPDATE
Here is the SQL I'm using to try and replace the table contents:
LOAD DATA INFILE 'https://www.mystagingserver.com/xyz.csv'
REPLACE
INTO TABLE wp_loans
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
IGNORE 1 LINES
I would recommend a cron job to automate the process, and probably use BCP (bulk copy) to insert the data into a table... But seeing as you are using MySQL, instead of BCP, try load data in file - https://mariadb.com/kb/en/load-data-infile/

Load Local Data Infile with a condition in MYSQL 5.0

I am having a question.
I have to upload a file into mysql 5.0 DB.
but inside the file it has 2 kinds of information, details and header.
it is like
H12345678900TYPE
L12334567TYPE
and the file is not delimited, it is fixed position.
I want to load the lines which starts with H only and also has the type as TYPE.
is there anyway I can check inside the load query?
i tried WHERE SUBSTR(#var1,1,1)='H'
but it says the syntax error.
Any suggestion???
Thanks
It will be better if you load file first in a temp table. and in next step import from temp table to your main table with applying condition.

populating mysql database

I have a file with over a million lines of data, each line is a record.
I can go through the file, read the line and do a insert, but this can take up to 2 hours. Is there a faster way like uploading a sql file?
Use LOAD DATA INFILE
You can use Find and replace to build an insert statement around it.