How to do automatic mysql db backup using mysql workbench - mysql

How to do automatic mysql db backup using mysql workbench?
Is it possible?

Mysql bench is not required for automatic backup,
setup a crontab and use mysqldump (or equivalent) will do the same job and is easier.
example:
crontab -e
/* backup every day at 00:00:00 */
0 0 * * * mysqldump -u root -ppassword YOUR_DATABASE > /backup/YOUR_DATABASE.sql

If you have a webserver with PHP I'd suggest MySqlDumper
It supports:
Automatic backups
Emails backups
Compresses backups
Rotates backups
etc.

ATM scheduled backups are not plannned in Workbench:
http://bugs.mysql.com/bug.php?id=50074
At the same time Workbench is designed to have powerful scripting shell, so you can try to
investigate what commands can be used for backup and call them directly from shell.
(But I agree this is too general idea):
http://dev.mysql.com/doc/workbench/en/wb-extending.html

Related

MySQL Incremental backup

I have a mysql server, try to take backup of database on daily bases only changes needed for backup and please provide how to setup incremental backup on mysql
While Percona Xtrabackup can do the job even for large databases, IMHO it is a bit complex to install and setup.
For small to medium databases a simpler approach uses a combination of mysqldump and rdiff-backup to obtain an incremental mysql backup. Something like this:
#!/bin/bash
mysqldump --single-transaction --quick --skip-extended-insert --routines -umyuser -pmysecret dbname > /path/to/dumps/dir/dbname.dump;
rdiff-backup /path/to/dumps/dir/ /path/to/backup/dir/
On my blog you can read more details on how to perform MySQL incremental backup with mysqldump and rdiff-backup.
There are two tools available in the market which supports the incremental backup 1- Percona Xtra Backup; it is free and easy to use 2 - mysqlbackup, this comes with enterprise MySQL license only.

How to backup whole MySQL database with all users and permissions and passwords?

I need to backup the whole of a MySQL database with the information about all users and their permissions and passwords.
I see the options on http://www.igvita.com/2007/10/10/hands-on-mysql-backup-migration/,
but what should be the options to backup all of the MySQL database with all users and passwords and permissions and all database data?
Just a full backup of MySQL so I can import later on another machine.
At it's most basic, the mysqldump command you can use is:
mysqldump -u$user -p$pass -S $socket --all-databases > db_backup.sql
That will include the mysql database, which will have all the users/privs tables.
There are drawbacks to running this on a production system as it can cause locking. If your tables are small enough, it may not have a significant impact. You will want to test it first.
However, if you are running a pure InnoDB environment, you can use the --single-transaction flag which will create the dump in a single transaction (get it) thus preventing locking on the database. Note, there are corner cases where the initial FLUSH TABLES command run by the dump can lock the tables. If that is the case, kill the dump and restart it. I would also recommend that if you are using this for backup purposes, use the --master-data flag as well to get the binary log coordinates from where the dump was taken. That way, if you need to restore, you can import the dump file and then use the mysqlbinlog command to replay the binary log files from the position where this dump was taken.
If you'd like to transfer also stored procedures and triggers it's may be worth to use
mysqldump --all-databases --routines --triggers
if you have master/slave replication you may dump their settings
--dump-slave and/or --master-data
Oneliner suitable for daily backups of all your databases:
mysqldump -u root -pVeryStrongPassword --all-databases | gzip -9 > ./DBBackup.$(date +"%d.%m.%Y").sql.gz
If put in cron it will create files in format DBBackup.09.07.2022.sql.gz on a daily basis.

export table using ssh

I want to export a table of mysql database using ssh so how can I take this one.
Export the table to a file, using MySQLDump, PHPMyAdmin or your favorite tool.
Transfer the file to the host of your liking, using scp or your favorite tool.
What do you mean "export using SSH?" SSH is a protocol to securely talk to a server. SCP is a way to copy files between hosts using SSH, so I assume you mean that.
mysqldump db_name tbl_name >dumpfile
scp dumpfile 127.0.0.1:.
If you dislike mysqldump, you can always just SELECT INTO OUTFILE from your favorite MySQL client (or PHP program, or just the commandline mysql). After that you transfer the file to the other host, and run LOAD DATA INFILE to load the table. You'll have to recreate the table as well.
mysqldump -uuser -ppass dbname tablename >dump_table.sql
If the dump is going to be very large, you'll probably want to run it in the background, to assure you losing connection to SSH doesn't cause a problem.
Also, you could use nice if it is a live server and don't want to effect its performance too much
nohup nice mysqldump -uuser -ppassword [other flags] database tablename > dumpfile.sql
You can then use SSH File Transfer to download it to your computer, or use scp to send it to another server:
nohup nice scp dumpfile.sql user#IP:/path/ &
Then you can load it in to mysql
nohup nice mysql -uuser -ppassword database < dumpfile.sql &
**Use nohup if its going to take a long time and losing connection could be a problem. nohup causes to run in background
**Use nice to lower the priority of the process, ie. in case is live server and performance is important. You should know nice doesn't stop your mysql from being slowed down by a query that takes a long time to finish, so beware.

How to backup my MySQL's databases on Windows Vista?

How can I backup my MySQL's databases? I'm using Windows Vista and MySQL 5.1.
I have found the folder "C:\Users\All Users\MySQL\MySQL Server 5.1\data" with all my database files and copy them, but how can I restore them if I need?
Thank you.
You could use the mysqldump tool:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
That way you'd get SQL files that you could just execute.
You can also go surf to localhost/phpmyadmin and go to 'export' and select the databases you want to export.
The backup process does not have anything to do with your operating system. Simply export your databases.
You can back up the database files directly, but this can be dangerous if the database is in active use at the time you do the backup. There's no guarantee that you'll make a consistent and valid backup if a query starts modifying on-disk data. You may end up with broken tables.
The safest route is to use mysqldump to output a set of sql statements which can recreate the database completely (table creation + data) in one go. Should you need to restore from backup, you can simply feed this dump file back to mysql:
mysqldump -p -u username nameofdatabase > backup.sql
and restore via:
mysql -p -u username nameofdatabase < backup.sql
The .sql file is just a plaintext dump of all the queries required to rebuild the table(s) and their data.

In MySQL, what are the practices to backup databases?

I am using mysql
How often do you back up your database?
How do you normally backup your database?
Export all data into sql or cvs format and keep it in a folder??
Setting up a cronjob to run a script that does a mysqldump and stores the dump on a separate disk from the database itself (or a remote server) is a quite easy and efficient way to backup a database in my opinion. You could even have it dump every database with the --all-databases switch
If you have more than one MySQL server, you could also use replication
Frequency of backups depends on how much data you are willing to lose in case of a failure.
How Often - Depends on the activity and traffic you have on your Database.
I use phpMyAdmin and then click on the export tab and export the database as .sql
you can reach phpmyadmin by either localhost/phpmyadmin if you are running xampp/wamp/lamp etc or you can click on the 'phpmyadmin' link in your webhost's cPanel if you are hosting your webstie online.
I backup databases daily, using 'mysqldump [options] db_name [tables]', and export all data into sql.
Of course, this depend on the size of your databases.
I use mysqldump:
mysqldump -uroot -p database_name > ~/backups/database_name-$(date +%s).sql
1.If you want the easiest way to back-up the database then you can opt for phpMyadmin.
2.If you prefer command line then follow this way.
You would simply modify the path and filename to reflect the specifics of your new backup file, like so:
C:\ mysql -uroot -p [DatabaseName] < C:/backups/[backUpDatabaseName.sql]
3.Mysql dump.
C:\ mysqldump [myDatabaseName] > [ExportDatabaseName]
You can also look hotbackup