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?
Related
i have issue to daily backup for mysql database.
export only all tables with data but not mysql function and stored procedure.
how to get full database backup?
I have use this cronjob.
mysqldump –opt -Q -h [myhost] -u myusername –p"*****" ebooklibrary > /fullpath.../_db_backups/openelibrary.sql
Add the "--routines" option, which is off by default in the query. This should give you the desired result. I hope this helps.
Read more here.
mysqldump --routines –opt -Q -h [myhost] -u myusername –p"*****" ebooklibrary > /fullpath.../_db_backups/openelibrary.sql
I need to restore just a single table in my database.
I have a .sql file that has all the info I need for one table but the rest would overwrite important information for other tables.
Instead of using the solution here - using a tool I've never heard of, I figured it would be more sure fire to do it manually.
Unfortunately, the MySqlDump generated a GIANT insert line too long to paste into mysql command line...
What should I do?
Should I use sed like the link above describes?
Or could I copy paste the commands for that specific table from the mysqldump.sql into a new .sql file then call:
mysql -u root -p -h localhost < copyPasteFile.sql
u can try it
mysql -u root -p databasename -h localhost < copyPasteFile.sql
mysql -uuser -ppassword -e "create database temporary"
mysql -uuser -ppassword temporary < copyPasteFile.sql
mysqldump -uuser -ppassword temporary yourtable > onlythattable.sql
mysql -uuser -ppassword therealdb < onlythattable.sql
mysql -uuser -ppassword -e "drop database temporary"
make sure that copyPasteFile.sql does not have a "use somedatabase;" if it was exported with phpmyadmin, it probably has that, if it was exported with mysqldump it wont.
I am not sure if its the best way but I just spin up a new schema and restore the backup in to it, Dump the data I need and import that in to the production database.
I use the MYSQL work bench which makes it easier but the below steps can probably be reproduced at the command line
Create new MYSQL Schema
Import self-contained backup
Set "Target Schema" to the new empty database (.sql Dump must not contain schema creation code)
Restore backup
Dump table to csv and import it in to the production live database
Delete Restore Schema
To restore to a schema at the command line it looks like you use:
mysql -u <user name> -p <password> <database name> < sqlfilename.sql
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
This is working:
exec('mysqldump --single-transaction --user=myusername --password=mypassword --host=localhost mydb > /home/path/public_html/a.sql');
exec('mysql --user=myusername --password=mypassword --execute="drop database mydevdb;"');
exec('mysql --user=myusername --password=mypassword --execute="create database mydevdb;"');
The SQL file gets created with the queries in it from the live db, in the right place, the dev db is dropped and recreated. Note that the first exec only works with --single-transaction. But the last step, below, is not working. It creates the first table, with no data, and no other tables. I've tried it with and without --single-transaction.
exec('mysql --user=myusername --password=mypassword --host=localhost mydevdb < /home/path/public_html/a.sql');
What I really want is to clone one database to another within the same MYSQL instance via PHP. This doesn't work either:
exec('mysqldump --user=myusername --password=mypassword --host=localhost mydb | mysql --user=myusername --password=mypassword --host=localhost mydevdb');
So I am trying to dump and then import. Any ideas?
Its been to late to answer here but there is a way to Clone database using below command.
exec('mysql --user=myusername --password=mypassword --execute="drop
database new_dbname"');
exec('mysql --user=myusername --password=mypassword --execute="create
database new_dbname"');
exec("mysqldump --events --ignore-table=mysql.events -u $myusername
-p'$mypassword' $existing_db_name | mysql -u $myusername -p'$mypassword' -C $new_dbname");