Taking a MySQL snapshot and recreating the database? - mysql

If a snapshot of the database is taken, can it be copied over to another drive and re-created?

I'm not sure what you mean by "copied over to another drive", but a very good tool to create a snapshot of a running database is mysqlhotcopy.
mysqlhotcopy is a Perl script that was originally written and contributed by Tim Bunce. It uses FLUSH TABLES, LOCK TABLES, and cp or scp to make a database backup. It is a fast way to make a backup of the database or single tables, but it can be run only on the same machine where the database directories are located.

Related

Can I backup multiple mysql databases (All InnoDB) without using mysqldump and just using file/folder backup

Is there any way where I can take a backup of some files/folders to take the backup of all my Mysql databases. I am using Acronis Cloud Backup tool and I dont find any option where I can backup mysql database. It is either Drive/Folder or entire machine. Need an approach without using mysqldump. Instead I am looking at directory/files backup
Also it is NOT a linux machine so cron & shell script cannot be used. It is windows 2016 server.
What is the best approach to backup multiple mysql databases which in emergency can be restored reasonably fast and accurately.
Thanks
Kalpak
You can backup the complete folder
C:\ProgramData\MySQL\MySQL Server 8.0
And after reinstalling you copy all folder/files back.
I had to do it last week, so i am sure that it works, but you need all files.
And this is not incremnetal.

Can a mysql backup be transfer by copying and pasting data files from the mysql dir?

I need to reformat my computer and reinstall the OS. I have plenty of databases that are connected to sites running on my XAMPP stack. If I copy an paste the data files from the mysql folder into a new XAMPP stack, will the databases be preserved? If so, which files need to be copied? Are there other considerations? Also, is there a difference if the destination stack is LAMP or WAMP?
I strongly advice you don't try to backup/restore a MySQL database simply copying the files.
Although that can be done with MyISAM tables, InnoDB tables won't work simply by copying files.
If you need to move the databases from one instance to another, I recommend you use mysqldump to create database backups.
Sugested reads:
mysqldump - A database backup program
Using mysqldump for Backups
Copying MySQL tables, InnoDB tables not recognized (at dba.stackexchange)

MySQL .frm/.myd/.myi

I have a MySQL database with test data. I have been modifying routines and triggers in this database. I have a new .tar file containing *.frm, *.myd, *.myi, *.trn, and *.trg files for this same database with production data. I want to take only the actual data from the tar file and move it into my existing database. May I simply move the *.myd and *.myi files from the tar file to the current folder for my database without corrupting the schema?
Yes, you should be able to do that just fine. frm, myd and myi are MyISAM tables and you can copy and moves those around without corrupting anything. Although, technically you should have the database shutdown when you do that. If that is not an option, make sure you run "flush tables" before copying anything.
Once you copy those into the mysql data directory, make sure the privileges are correct. Then you should be able to see them in mysql. As I said, you can do this while mysql is running, but I don't recommend it.
You cannot do this with Innodb tables (i.e. .ibd extension).

Automatic Replica Database of mySql database for backup?

I have mysql database in my web project. I need to create a replica of my mysql database for backup.
My web interface interacts directly with one database, i need that other backup database to get automatically updated whenever there are some changes in main or master database.
How can I automate this process of backup database ?
You will have to run a cron periodically to check for changes. If there is a change, then you can get a backup of your database.
For example:
You can run a cron every 5 minutes(depending on how often you need a backup) and check if the latest record was added in the last 5 minutes. If yes, run the mysqldump command to get the backup.
Typically you create master/slave setup. Periodically you take the slave down and make a copy of the database using rsync. Alternatively, you can leave the slave up and do a mysqldump, but that takes a lot longer to restore.

mysql restore for files on another server

I have a test database on a separate remote server than my production DB. Every once in awhile, I want to try and test things by uploading a copy of my production DB to my testing DB. Unfortunately, the backup file is now half a gig and I'm having trouble transferring it via FTP or SSH. Is there an easy way that I can use the mysql restore command between servers? Also, is there another way to move over large files that I'm not considering? Half a gig doesn't seem that big, I would imagine that people run into this issue frequently.
Thanks!
Are the servers accessible to each other?
If so, you can just pipe the data from one db to another without using a file.
ex: mysqldump [options] | mysql -h test -u username -ppasswd
0.Please consider whether you really need production data (especially if it contains some sensitive information)
1.The simplest solution is to compress the backup on the source server (usually gzip), transfer it across the wire, then decompress on the target server.
http://www.techiecorner.com/44/how-to-backup-mysql-database-in-command-line-with-compression/
2.If you don't need the exact replica of production data (e.g. you don't need some application logs, errors, some other technical stuff) you can consider creating a backup and restore on a source server to a different DB name, delete all unnecessary data and THEN take a backup that you will use.
3.Restore full backup once on your reference server in your Dev environment and then copy transaction logs only (to replay them on the reference server). Depending on the usage pattern transaction logs may take a lot less space as the whole database.
Mysql allows you to connect to a remote database server to run sql commands. Using this feature, we can pipe the output from mysqldump and ask mysql to connect to the remote database server to populate the new database.
mysqldump -u root -p rootpass SalesDb | mysql --host=185.32.31.96 -C SalesDb
Use an efficient transfer method, rather than ftp.
If you have a dump file created by mysqldump, on the test db server, and you update it every so often. I think you could save time (if not disk space) by using rsync to transfer it. Rsync will use ssh and compress data for the transfer, but I think both the local and remote files should/could be uncompressed.
Rsync will only transfer the changed portion of a file.
It may take some time to decide what, precisely, has changed in a dump file, but the transfer should be quick.
I must admit though, I've never done it with a half-gigabyte dump file.