MySQL creating and populating the database - sql

I have downloaded the MySQL 5.2.5.1 version. I need to create the database and populate it. O have the data file in .csv format. I'm running the Mysql on windows. So when I create the database and a table in it, I want to populate the data from a file on my PC which is in .csv format.
I did it in this way:
load data local infile 'uniq.csv' into table tblUniq
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
But it is not working for me. Where I am making a mistake?

You might need to change
lines terminated by '\n'
to
lines terminated by '\r\n'

Related

How to transfer Excel data to My SQL Query Browser?

I have a problem to transfer Excel data to My SQL Query Browser? Someone can help me with how to transfer Excel data to SQL?
My excel data is store
C:\2019\countries.xlsx
My excel data is like below the picture:
Below is my SQL info, I won't put excel file data to column(id, name,country_code and language):
I hope anyone can guide me on how to use an easy way to insert data into the database. Thanks.
You need to convert into csv then use the below query to import.
load data local infile 'C:/2019/countries.csv' into table countries
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n'
ignore 1 lines;
You can refer the detail in docs here
Note: If using Windows terminate by '\r\n' use '\n' on Linux based OS.

lines terminated by '\n' is not working when moving the data from hive view to a hive external table

I have given the external table creation in hive below
create external table tablename (column details)
row format delimited
fields terminated by ','
lines terminated by '\n'
location 'location in which the data gets stored'
However, after the creation and loading of that external table. I see that the underlying data file in the folder is containing the data in a single line. i.e the newline setting is not working.
I am running the hiveql through Azure hd insight cluster

How can hive load data from csv?

I want to implement apache hive and I want to load the data from csv file to hive table. So, here's the problem :
my csv file generated by SQL Server in it's structure have " sign, and it's become something like "04748/09","2248559","2248559","2009-12-03 00:00:00". So how can I only get the value without the " sign ?
Thanks a lot, I need your suggestions......
problem mention in your comment-how can I ignore the first line when import on hive like an mysql import?
From Hive v0.13.0, you can use skip.header.line.count. You could also specify the same while creating the table. For example:
Create external table testtable (name string, message string) row format delimited fields terminated by '\t' lines terminated by '\n' location '/testtable'
tblproperties ("skip.header.line.count"="1");
or
CREATE TABLE TEMP (f1 STRING, f2 String, f3 String, f4 String) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' TBLPROPERTIES("skip.header.line.count"="1");
load data local inpath 'test.csv'
overwrite into table TEMP;

Importing CSV to MySQL with Load Data Infile

I'm trying to load a CSV file into MySQL, and I keep getting syntax errors:
load data infile 'c:/worldminwage.csv' fields terminated by ',' enclosed
by '"' lines terminated by '\n' (YearlyWage, PercentGDP, Date
effective);
Can anyone help me get this working? Thanks.
Valid syntax is LOAD DATA INFILE 'c:/worldminwage.csv' INTO TABLE tablename.
You forgot to mention which table the data should go in. See LOAD DATA INFILE Syntax
I think This would be more batter
LOAD DATA INFILE 'c:/worldminwage.csv' fields terminated by ',';
Because you will get rid of error like columns numbers are not matching in the .csv file and mysql table

Hundreds of excel lookup values to MySQL inserts online?

I have hundreds of excel documents which have lookup values for all the lookup tables that I am giving to my developers. some are small and some are super huge like world cities. Either i can send them the xls file and let them import it into the DB but I prefer to send them the SQL inserts in a text file so they can just execute it and save time to load all the data.
Now I dont have any MySQL environment setup as i dont do development so the question is how do i convert the various colunms of lookup values on each excel tab into insert statements to load in? Are there any online tools that can read the xls and create sql inserts? I dont want to manually do it, the city table itself will take me a whole week if i put in 12 hours a day each day of the week to manually create the inserts for all the rows.
Within Excel, save your spreadsheets as CSV (comma separated values) files. Your developers will be able to load them into MySQL directly using LOAD DATA INFILE. If they create a table with columns that match the CSV columns, then your developers can import them with the following SQL command:
LOAD DATA INFILE 'file_name.csv'
INTO TABLE tbl_name
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES
TERMINATED BY '\r\n' -- or '\n' if you are on unix or '\r' if you are on mac
IGNORE 1 LINES -- if you want to skip over the column headings