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
Related
I've been migrating ddbb (a few GB size) in mySQL workbench 6.1, from one mySQL server to another mySQL. Never having done this before I thought it was 99% reliable. Instead, 2 out of 3 tries have failed.
My ddbb dont have complex features (triggers, SP & functions,...). The errors, though, are difficult to interpret, almost always about tables failing to export, reason unknown. There might be occasionally a duplicated key index in source, but that shouldn't prevent an export from happening?
I've tried all the different methods available in the interface:
1) Server > Data Export > Data Import
2) Migration wizard
3) Schema transfer wizard
4) Reverse engineer
but no real difference.
Also, all methods seem variants of the same, do these menu options rely on the same procedure internally, how really different are they?
My questions are generic:
1) Is there a foolproof method, relaxed about errors, e.g. is
mysqldbcopy from myQL utilities much better that workbench wizards?
2) Does mySQL wizards configuration make any difference (e.g. a checkbox that causes errors by being too demanding if the source db has a problem) I just want to transfer the db, not perfection in the target server. I've switched SSL=NO, but still not working.
3) What is the single most important cause of errors in migration, e.g. server overloaded, enough memory, table structure?
Thanks in advance,
There might be occasionally a duplicated key index in source, but that shouldn't prevent an export from happening?
Yeah, It shouldn't prevent export operation.
I've tried all the different methods available in the interface:
All interface you have used might have some timeout configured so it don't really execute fully as your database is BIG.
So how to migrate MySQL database from one server to another?
To do it properly, I suggest you use command line like this:
Step 1: create backup file on old server
mysqldump -u [[user_name]] -p[[password]] [[db_name]] > db_backup.sql
Step 2: Transfer backup file to new server.
Step 3: Import backup file in new server.
mysql -u [[user_name]] -p[[password]] [[db_name]] < db_backup.sql
Pro tip:
you can combine step 1 & 2 if you have remote MySQL enabled on old server. Just execute this command on new server so it will download the backup file in current directory of new server.
mysqldump -h [[xxx.xx.xxx.xxx]] -u [[user_name]] -p[[password]] [[db_name]] > db_backup.sql
where [[xxx.xx.xxx.xxx]] represents ip address/hostname for old server.
Extra Note:
Please note that there is no space between -p and [[password]]. you can also omit the [[password]] if you think it's security issue to include password in command.
If you have access to your terminal you can try using "mysqldump" and also you could try percona xtrabackup tool.
Mysql dump : (If your DB is too large then I suggest you to use screens)
Backup all DB : mysqldump -u root -pxxxx --all-databases > all_db_backup.sql
Backup Tables : mysqldump -u root -pxxxx DatabaseName table1 table2 > tables.sql
Backup Individual databases : mysqldump -u root -pxxx --databases DB1 DB2 > Only_DB.sql
To import : Sync all the files to another server and try importing as show below
mysql -u root -pxxxx < all_db_backup.sql (Use Screen for large Databases)
Individual DB : mysql -u root -pxxx DBName < DB.sql
( Note : Before you import make sure your backuped file already has create database if not exists statements or you could create those DB names before importing )
This may seem like a very dumb question but I didn't learn it in any other way and I just want to have some clarification.
I started to use MySQL a while ago and in order to test various scenarios, I back up my databases. I used MySQL dump for that:
Export:
mysqldump -hSERVER -uUSER -pPASSWORD --all-databases > filename.sql
Import:
mysql -hSERVER -uUSER -pPASSWORD < filename.sql
Easy enough and it worked quite well up until now, when I noticed a little problem with this "setup": It does not fully "reset" the databases and tables. If, for example, there is an additional table added AFTER a dump file has been created, that additional table will not disappear if you import the same dump file. It essentially only "corrects" tables already there and recreates any databaes or tables missing, but does not remove any additional tables, which happen to have names that are not in the dump file.
What I want to do is to completely reset all the databases on a server when I import such a dump file. What would be the best solution? Is there a special import function reserved for that purpose or do I have to delete the databases myself first? Or is that a bad idea?
You can use the parameter --add-drop-database to add a "drop database" statement to the dump before each "create database" statement.
e.g.
mysqldump -hSERVER -uUSER -pPASSWORD --all-databases --add-drop-database >filename.sql
see here for details.
There's nothing magic about the dump and restore processes you describe. mysqldump writes out SQL statements that describe the current state of the database or databases you are dumping. It has to fetch a list of tables in each database you're dumping, then it has to read the tables one by one and write them out as SQL. On databases of any size, this takes time.
So, if you create a new table while mysqldump is running, it may not pick up that new table. Similarly, if your application software changes contents of tables while mysqldump is running, those changes may or may not show up in the backup.
You can look at the .sql files mysqldump writes out to see what they have picked up. If you want to be sure that your dumped .sql files are perfect, you need to run mysqldump on a quiet server -- one where nobody is running data definition language.
MySQL hot backup solutions are available. You may need to look into that.
The OP may want look into
mysql_install_db
if they want a fresh start with the post-install default
settings before restoring one or more dumped DBs. For
production servers, another useful script is:
mysql_secure_installation
Also, they may prefer to dump the DB(s) they created separately:
mysqldump -hSERVER -uUSER -pPASSWORD --database foo > foo.sql
to avoid inadvertently changing the internal DBs:
mysql, information_schema, performance_schema.
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 take the backup of full database using mysql?
You could use mysqldump. Have a look at the reference manual: 4.5.4. mysqldump — A Database Backup Program
[mysqldump] can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both.
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Here is an example using mysqldump, you can create an Scheduled task or a cron job to automatize the backup process:
mysqldump --opt --host=localhost --user=myUser --password=myPass --result-file=C:\Backups\myBackupFile.sql myDatabase
If you have access to phpMyadmin, try the export function as it's probably the easiest way.
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.