I'm using php to backup mysql database.
99% of this database is MyIsam table.
exec("mysqldump -u root -ppassword dbname | mysql -u root --password=password safe_dbname");
In this way, it is fast to back up but importing is very slow in php.
Is there any solution?
I'm using laravel and mysql as database, and I want to make a backup database in hosting with one click button in html, but I wonder what is the best query for them instead of query all data in all table with loop, then insert it one by one to host with loop. Thanks before
Use mysqldump
$ mysqldump -h <host> -u <user> -p<password> <database_name> > backup.sql
This will create a sql file backup.sql with all your data.
Note the missing space beween -p and <password>.
It's okay to give the password interactively (in which case, you'll have to skip the <password> part), but since you mentioned laravel in the question, I am assuming you want to code this and want it to be non-interactive.
EDIT:
Using code
Execute the command with exec()
$cmd = "mysqldump -h <host> -u <user> -p<password> <database_name> > backup.sql";
exec($cmd, $output, $return_value);
I am trying to create a batch file in Windows to backup a MySQL Database, i have tried this:
C:\xampp\MySQL\bin\MySQLDump –u root –p database_name –result-file=”C:\Users\Administrator\Desktop\MySQLDump.sql”
but i get an error saying:
Got error: 1044: Access Denied for user ``#`localhost` to database `?u` when selecting the database
The solution to this problem/error was to use one of these mysqldump commands:
mysqldump --opt --lock-tables=false -u USER -p DBNAME > dump.sql
mysqldump --opt --single-transaction -u USER -p DBNAME > dump.sql
http://alvinalexander.com/mysql/mysql-error-1044-access-denied-for-user-using-lock-tables
Try this, it worked for me.
Don't forget to replace values inside {} as you need
C:\xampp\mysql\bin\mysqldump.exe -u{username} -p{passwrod} database > {/backuppath}.sql
Completed guide can be found at here:
https://www.tectut.com/2016/04/automatically-backup-mysql-databases-on-windows/
I have got alldatabase.sql file
How I can restore data with it?
My console comand is not working:
mysqldump -u root -p < alldatabase.sql
I must to create database first, but all database in my one file. What I must to do?
You use mysqldump to take a snapshot, but you restore using the mysql command
mysql -u root -p < alldatabase.sql
I want to export a table data into a csv file using mysqldump.
I want to make something like:
mysqldump --compact --no_create_info --tab=testing --fields-enclosed-by=\" --fields-terminated-by=, -uroot -proot mydatabase mytable
but i keep getting this error:
(Errcode: 13) when executing 'SELECT INTO OUTFILE'
I made my testing folder writable(I'm using Ubuntu as enviornment). Can somenone explain how to export a table in a CSV file, or how to modify my command shell in order to work? Thanks!
The trouble with all these INTO OUTFILE or --tab=tmpfile answers is that it requires running mysqldump on the same server as the MySQL server.
My solution was simply to use mysql (NOT mysqldump) with the -B parameter, inline the SELECT statement with -e, then massage the ASCII output with sed, and wind up with CSV including a header field row:
Example:
mysql -B -u username -ppassword database -h dbhost -e "SELECT * FROM accounts;" |sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g"
"id","login","password","folder","email"
"8","mariana","57d40c8a954bc9e65f401592062019b1457be359","mariana",""
"3","squaredesign","b01134fac01dab765bcb55ab0ca33f9ec2885a7b","squaredesign","mkobylecki#squaredesign.com"
"4","miedziak","601f1889667efaebb33b8c12572835da3f027f78","miedziak","miedziak#mail.com"
"5","Sarko","480225f1ac707031bae300f3f5b06dbf79ed390e","Sarko",""
"6","Logitrans
Poland","9033b6b3c4acbb27418d8b0b26f4c880ea6dea22","LogitransPoland",""
"7","Amos","50f5604164db2d5ff0e984f973d2202d5358b6a6","Amos",""
"9","Annabelle","07e832cb64e66fa03c13498a26a5f8e3bdebddf1","Annabelle",""
"11","Brandfathers and
Sons","f08b194668249e4cb81fbb92df846e90569f5c01","BrandfathersAndSons",""
"12","Imagine
Group","e86f1645504c7d5a45ed41d16ecc39ed19181773","ImagineGroup",""
"13","EduSquare.pl","80c3c099f4ecc043a19f1527400d63588567a0ad","EduSquare.pl",""
"101","tmp","b01134fac01dab765bcb55ab0ca33f9ec2885a7b","_","WOBC-14.squaredesign.atlassian.net#yoMama.com"
Add a > outfile.csv at the end of that one-liner, to get your CSV file.