Loading MySQL dump file with bin extension - mysql

I know how to restore MySQL DB with *.sql files.
But i don't know how to import *.bin files. Content in this file is:
123456789|www.site-name.com
123789456|www.go.com
123987456|www.g1.net
987865432|www.site.org
Please help!

*.bin files are mysql logs. You can view these files with the command mysqlbinlog
http://dev.mysql.com/doc/refman/5.0/en/mysqlbinlog.html
BUT looking at the content of the file, it appears to be just plain text file with | as a column separator. (The default column separator in mysql is TAB.)
You can load file with the following command
LOAD DATA INFILE '/path/to/file.bin'
INTO TABLE table_name
FIELDS TERMINATED BY '|'
http://dev.mysql.com/doc/refman/5.0/en/load-data.html

Related

Why can I not locate a .csv file when using LOAD DATA LOCAL INFILE?

I'm using MySql version 5.6 on a Mac running MAMP. I've set my document root to user/Desktop/Sites/Rankings. I'm trying to upload a CSV file into a table using the following code:
LOAD DATA LOCAL INFILE 'teams.csv' INTO TABLE Teams
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r'
IGNORE 1 LINES
(team_id, team_location, team_name, team_abbrv);
I keep getting the following error message:
ERROR 2 (HY000): File 'teams.csv' not found (Errcode: 2 - No such file or directory)
I've tried changing a bunch of things based on research done on this site with no luck. I've confirmed read/write permissions on the file and and made sure local_infile is ON. I'm starting to wonder if I'm not pointing in the right direction. When I use LOCAL, does that mean I should be putting my .csv file in the same document root file (Rankings) that I've set up in MAMP? That's what I've done, but it still doesn't seem to be working. I'm going crazy! Thank you for the help.
Had the same problem myself and was not liking a full path to a file, kept saying file not found.
What worked for me is I found the data directory and put the CSV file in there and it would load the file locally from that directory.
/usr/local/var/mysql/dbname/file.csv
LOAD DATA INFILE 'file.csv' INTO TABLE dbname.table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;
Hope it saves someone the 30 minute headache I had.

Loading .csv File into SQL Server using SSIS Technique

I am new to SQL Server and SSIS. I want to shedule the loading of .csv file into SQL Server.I want to run the loading for a specific time daily.Please help.Thanks in Advance.
You can do this by first creat the table(s) in SQL with the appropriate data types. Then by importing into SQL first and then write your script to update the table but a .bat file would require in order to run your scripts. The following is an example command for a .bat file: sqlcmd -S ServerName -U UserName P Password -i "C:\folder\update.sql"-o "C:\folder\output.txt"
You will need to write the .csv file to a text file and change the extension to .sql
You can use the "Bulk Insert Command"
Example:
BULK INSERT FILENAME
DATABASENAME.DBO.TABLENAME
FROM 'C:\sqlscript\fileName.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
Hope this helps

Load data infile MySQL with absolute URL

i trying load a CSV in a table.
I have my CSV in a folder of my server. (wwww.myweb.com/temp/file.csv)
I use this sentence:
LOAD DATA INFILE 'http://wwww.myweb.com/temp/file.csv' INTO TABLE ga_tmpActivosDocumentos FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES (idTipoSuelo,C_Latitud,C_Longitud,Referencia,Zona,idProvincia,Poblacion,TituloActivo,Descripcion,Superficie,Gastos,Equipamiento,EquipamientoEN,GestionDocumental,PrecioVenta,CampoLibre1_Texto,CampoLibre1_Titulo,CampoLibre1_TextoEN,CampoLibre1_TituloEN,Activo, IMG1,IMG_Desc1,IMG_Desc1EN,IMG2,IMG_Desc2,IMG_Desc2EN,IMG3,IMG_Desc3,IMG_Desc3EN,IMG4,IMG_Desc4,IMG_Desc4EN,DOC1,DOC_Desc1,DOC_Desc1EN,DOC2,DOC_Desc2,DOC_Desc2EN,DOC3,DOC_Desc3,DOC_Desc3EN,DOC4,DOC_Desc4,DOC_Desc4EN,URL1,URL_Desc1,URL_Desc1EN,URL2,URL_Desc2,URL_Desc2EN) SET idCliente = 23
The sentence not work for me. I try to change the path to .../temp/file.csv, and other combinations but not work.
Also use "LOAD DATA LOCAL INFILE" but does not work.
I have read other topics, but only look examples with a relative URL, never absolute.
Thanks, and sorry for my english
#vadym-tyemirov answer works but if you don't want to create a temporary file, one solution is to load it from '/dev/stdin' and pipe it to the mysql cli:
wget -O - 'http://wwww.myweb.com/temp/file.csv' |
mysql \
--user=root \
--password=password \
--execute="LOAD DATA LOCAL INFILE '/dev/stdin' INTO TABLE table_name"
Save CSV file on your LOCAL computer.
Connect to the DB from your LOCAL computer
Issue the following command: load data LOCAL infile '/tmp/file.csv' INTO TABLE table_name;
You can also load data files by using the mysqlimport utility; it operates by sending a LOAD DATA INFILE statement to the server. The --local option causes mysqlimport to read data files from the client host.
MySQL cannot access the file in that location. Try moving it somewhere simple like /tmp (or copy it) on the local filesystem, and not via a URL parameter.
The MySQL process likely cannot load the folders BEFORE "temp/file.csv"

How to import sql file to database ignoring X lines in file?

I'm trying to import pretty large .sql file to mysql database. However After some time of importing it, I encountered an error, so I want to fix it, and continue importing from the specific line of this file (when I ended last time), is this possible?
You can use tail along with the MySQL Command-Line Tool if you are on a unix like system like Himanshu mentioned. The command would be:
tail -n +100 dump.sql | mysql -u user -p -D database
Note: You may run into problems starting part of the way thru a file because there may be references to values set at a previous point in the file.
Next time you can try to import mysql file with -f to ignore the errors:
-f, --force Continue even if we get an SQL error.
You can use IGNORE number LINES syntax to do this:
The IGNORE number LINES option can be used to ignore lines at the start of the file. For example, you can use IGNORE 1 LINES to skip over an initial header line containing column names:
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
See also:
LOAD DATA INFILE Syntax in official documentation

mysql load data infile can't get stat of file Errcode: 2

I have looked all over and found no solution, any help on this would be great.
Query:
LOAD DATA INFILE '/Users/name/Desktop/loadIntoDb/loadIntoDB.csv'
INTO TABLE `tba`.`tbl_name`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(
field1, field2, field3
)
Error:
Can't get stat of '/Users/name/Desktop/loadIntoDb/loadIntoDB.csv' (Errcode:2)
NOTE:
I'm running MySQL Query browser on OSX 10.6.4 connecting to MySQL 5.x
Things I've tried:
Drag-n-drop
Chmod 777
Put in a folder with 777 permissions
as well as the file having 777
permissions
try to use LOAD DATA LOCAL INFILE instead of LOAD DATA INFILE
otherwise check if apparmor is active for your directory
I had a similar problem. The resolution was a mildly ugly hack, but much easier to remember than apparmor workarounds provided that you can 'sudo'. First, I had to put the input file in the mysql sub-directory for the database I was using:
sudo cp myfile.txt /var/lib/mysql/mydatabasename
This does a copy and leaves 'root' as the file owner. After getting into mysql and doing a USE mydatabasename, I was able to populate appropriate table using
LOAD DATA INFILE 'mytabdelimitedtextfile.txt' INTO TABLE mytablename;
Using --local parameter will help with this.
Example: mysqlimport --local databasename file.txt -p
source:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
"The --local option causes mysqlimport to read data files from the client host"
For me, copying the contents to /tmp and using that as the source folder did the trick.
I use MariaDB, and my version does not allow using the "LOCAL" modifier.
Interestingly, giving read-write access to the CSV folder did not work either.
I had the same problem while populating a table in mysql on a AWS instance.
In my case i had the csv file in the instance itself.
Putting the Absolute path solved my problem.
Here's the line from MySQL documentation
If LOCAL is specified, the file is read by the client program on the client host and sent to the server. The file can be given as a full path name to specify its exact location. If given as a relative path name, the name is interpreted relative to the directory in which the client program was started.
http://dev.mysql.com/doc/refman/5.7/en/load-data.html