Importing zipped files in Mysql using command line - mysql

Importing zipped files in Mysql using CMD
What is the right syntax to import sql zipped files into mysql using cmd ?
I am doing the following
xz < backup.sql.gz | mysql -u root test
But always getting the following error

Try:
unzip -p dbdump.sql.zip | mysql -u root -p yourdbname
The dbdump.sql.zip should contain a single SQL file.
The -p flag pipes the output into the mysql binary.

I got the answer from my other question.
This is the command to import zipped file when you are using 7zip
7z x -so backup.7z | mysql -u root test
x is the extraction command
-so option makes 7-zip write to stdout

zcat backup.sql.gz | mysql -u[username] -p[pswd] [db]

You want might to try xz −−decompress −−stdout to decompress.
Full command would be xz −−decompress −−stdout backup.sql.gz | mysql -u root test

Related

Error ASCII '\0' when importing 29GB .sql file into mysql 5.7 database on Ubuntu 22.04

I have 29GB magento db .sql file that need to be imported into mysql database, I am using Ubuntu 22.04 operating system
I import into database using command line as below
mysql -u root -p
mysql > USE magento_project1
mysql > source db_dump.sql
The import seems to be working fine at first, but after a few hours of importing error as below comes out
ERROR at line 44259: ASCII '\0' appeard in the statement, but this is not alllowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: '
Attached the image of the error
I noticed the query stopped when at the part it need to insert data into sales_order_payment table
I have try
rename the db_dump.sql file to db_dump.sql.gz
based on solution given here
import using command mysql -u root -p -f -D database_name < db_dump.sql.gz
when create database, create charset as utf8mb4, collation utf8mb4_general_ci
import using command mysql -u root -p -h localhost -D database_name --binary-mode -o < db_dump.sql
based on solution given here
When i write command file db_dump.sql.gz I get the result as below
db_dump.sql.gz: ASCII text, with very long lines (37268)
My ubuntu is already sudo apt-update and sudo apt-upgrade with mysql, php, nginx and elasticsearch installed and enabled
But none of the solution above fix the issue I am having
Able to fix the issue by dumping new database from magento cloud using command below
magento-cloud db:dump
0 -> Staging -> 0 ( database )
then import the db into local using command below
mysql -u root -p -f -D local_db < dumped_db.sql
Not sure what cause the error above on the first place, might be the db corrupted somewhere during transfer between pendrive ?

How to download, unzip and import to mysql dump all via piping?

Is it possible to unzip a gzipped file while it's downloading and feed it to mysql all in one go without having to create a physical file?
So far I've been able to unzip and feed it to mysql using the following:-
gunzip < somefile.sql.gz | pv | mysql -u myself -p somedb #pv for viewing process
The above process expects the gzipped file to be downloaded already while unzipping and feeding it to mysql.
But I haven't been able to feed to mysql while it's unzipping and downloading simultaneously.
And if this is not possible I'd like to know the why too so as to get a peace of mind.
wget -qO- URL | gunzip | pv | mysql -u myself -p somedb
Okay, I've figured out. Thanks to #TGray for pointing me to the right direction.
The key was named pipes. Basically, you create a named pipe and start the download on that named pipes while piping that named pipe to gunzip as shown above in my post.
mkfifo mypipe
ssh username#server.com cat /source/file.gz > mypipe &
gunzip < mypipe | pv | mysql -uusername -ppassword dbname

SQL syntax error near gunzip when restoring a database using .sql.gz file

I am trying to restore a mysql db using a .sql.gz file. I am using mySql console to run a command because file size is too large for phpMyAdmin. Command I am using is
gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
where root is the user id. There is no password for root. bd is the database to which I am trying to import. mysql is running on my local machine (Windows 8). I have a wamp setup.
This is the error I am getting:
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'gunzip
C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql | mysql -u root
-p' at line 1.
You need -c option (output to stdout)
gunzip -c xxx.sql.gz |mysql -u root -p
While Kisoft´s answer is the correct one, I just wanted to point out that you don´t need the -c, it works just fine as it is.
this command will unzip the database dump and import it into the database at the same time.
gunzip < output.sql.gz | mysql -u <username> -p<password> <database>
If you type gunzip and you get a SQL syntax error that complaints about gunzip, you are already logged into the mysql console. The mysql console is not a general purpose shell!
You are using Windows and I suspect you haven't installed gzip in your computer (it isn't a builtin utility). It's a classical Unix tool but you can find binaries for Windows. Install it and run your original command with a couple of tweaks:
Make sure you're in Windows prompt (C:\>)
Redirect gunzip result to stdout rather than a file:
gunzip --stdout C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
Alternatively, you can run the dump from within MySQL promt (mysql>) if you uncompress it first (you don't need specifically command-line gzip, most GUI archivers such as 7-Zip support this format):
mysql> \. C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql
you do not need to gunzip
just:
zcat myfile.gz | mysql -uuser -ppassword mydatabase
it is faster this way
Your answer is already here
phpMyAdmin: Can't import huge database file, any suggestions?
Under php.ini file, normally located in c:\xampp\php or wampp whatever you called
post_max_size=128M
upload_max_filesize=128M
Changing value there will get you what you want.Good luck
Dont forget to restart , apache and mysql .
Try this following steps to restore db using .gz files:
1. Run command : gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz
This will uncompress the .gz file and will just store beed_2013-04-06.sql in the same location.
2. Type the following command to import sql data file:
mysql -u username -p bd < C:/Vik/Gya/Source/beed_2013-04-06.sql

How do I import data from a .bat file in MySQL?

I created a .bat file (import_file.bat):
set database_name=nome_db
mysql –u root --password=pass --database %database_name% < c:/import_geco/sql_svuta.sql
mysql –u root --password=pass --database %database_name% < c:/import_geco/carica_dati.sql
From the command line, in the MySQL bin directory I entered:
mysql/bin>c:/import_db/import_file.bat
... but it doesn't work, instead it returns MySQL help info.
If I create a .bat file to export table (export.bat):
mysqldump --no-create-info -u root nome_db nome_tabella > c:/backup_db/export.sql
... and enter at the command line:
mysql/bin>c:/import_db/export.bat
it works.
You get the help file because you have a malformed command. You are attempting to pipe something to the command line. YOu probably need to use the -e (--execute) command, and you can either pipe the file or use LOAD DATA FILE
see: http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html

How do I load a sql.gz file to my database? (importing)

is this right?
mysql -uroot -ppassword mydb < myfile.sql.gz
No, it isn't. The right way would be
zcat myfile.sql.gz | mysql -u root -ppassword mydb
Note there can be no space between the -p and password if using the -p syntax, refer http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_password
Use the following command:
gunzip < databasefile.sql.gz | mysql -u root -p dbname
You must not use the password directly in the terminal, use without it like follows
zcat YOUR_FILE.sql.gz | mysql -u YOUR_DB_USERNAME -p YOUR_DATABASE_NAME
Hit enter and when terminal asked for your password, type your password and hope everything will work fine.
Straight and clear:
gunzip -c myfile.sql.gz | mysql -uroot -ppassword mydb
-c option for gunzip writes to stdout, keeps original files
NOTE: You shouldn't put the password directly in the command. It's better to provide just -p and than enter the password interactively.
For Generating dbName.sql.gz
mysqldump -u <YOUR USERNAME> -p<YOUR PASSWORD> <YOUR DBNAME> | gzip > ~/mysqlBackup/dbName_`date +%Y%m%d%H%M`.sql.gz
For Loading dbName.sql.gz
zcat ~/mysqlBackup/<.SQL.GZ file> | mysql -u <YOUR USERNAME> -p<YOUR PASSWORD> <DATABASE NAME IN WHICH YOU WANT TO LOAD>
On windows you can do this:
First step! Install gzip for windows. I recommend using chocolatey to do it: (https://chocolatey.org/install)
choco install gzip -y
Now you can descompress your gz file and send it to mysql:
gzip -cd backup.sql.gz > mysql -uUSER -pPASSWORD -hLOCALHOST DATABASE
Good luck!
You have to follow below steps:
First check Mysql service should be running.
Then if you have compressed file, decompress it first.
Then you will find .sql file after decompressing.
Then find import data in left corner in Mysql.
Select option import from self-contained file and select
your .sql file and specify a new schema name.
Then click on import data.
After importing you will see your new schema in
available schema list.