Is there a way of synchronizing two databases as a batch process?
I have a database on my server but i want to have the same database
running on localhost , i know i can download the entirely database and import it
to localhost but
is there a way to import it once and then just run the insert,update,delete querys
that have been done on the server?
is there a log where queries that have been runned are stored? (queries not resultsets)
So far the only way i found it possible was to keep data structure and import all the data every day
Thanks !
I believe there is software to actually do this (version control and push/replicate databases). Off the top of my head, something available for sql server and mysql is called Redgate (http://www.red-gate.com/). Alternatively docker might offer a similar service but for mysql (https://docker.com/).
I think you can run a cron to do so ... Meaning write a script for exporting database from server and import the same using mysqldump command so in that way you would be able to synchronized the same..
to see the log of my sql queries.. please follow this
Edit mysql configuration file:
vi /etc/my.cnf
This will only log slow queries. You need the general log if you want to see all queries.
general_log = 1
general_log_file = "/opt/lampp/logs/query.log"
Note that you'll need to restart the server for this to take effect. Also, you should only use this type of logging during testing as it does cause slowdown.
for more in detail how-to-enable-general-query-log-in-mysql-under-linux
Related
Quick help here...
I have these 2 mysql instances... We are not going to pay for this service anymore; so they will be gone... How can I obtain a backup file that I can keep for the future?
I do not have much experience with mysql, and all threads talk about mysqldump, which I don't know if its valid for this case. I also see the option to take a snapshot but I want a file I can save (like a .bak).
See screenshot:
Thanks in advance!
You have several choices:
You can replicate your MySQL instances to MySQL servers running outside AWS. This is a bit of a pain, but will result in a running instance. http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Exporting.NonRDSRepl.html
You can use the commandline mysqldump --all-databases to generate a (probably very large) .sql file from each database server instance. Export and Import all MySQL databases at one time
You can use the commandline mysqldump to export a database at a time. This is what I would do.
You can use a gui MySQL client -- like HeidiSQL -- in place of the commandline to export your databases one at a time. This might be easier.
You don't need to, and should not, export the mysql, information_schema, or performance_schema databases; these contain system information and will already exist on another server.
In order to connect from outside AWS, you'll have to set the AWS protections appropriately. And you'll have to know the internet address, username, and password (and maybe port) of the MySQL server at AWS.
Then you can download HeidiSQL (if you're on windows) or some appropriate client software, connect to your database instance, and export your databases at your leisure.
For some technical reasons, I have to migrate our actual server, running on CentOS, to a new server, but running on Ubuntu.
I MUST keep the SQL DB as it is now, same version of MySQL, etc.
I have tried several dump scripts and methods, but impossible to import the dumps to a newer version of MySQL.
So I'm thinking of copying the /var/lib/MySQL folder and other MySQL folders to the new server.
What's your opinion about this ? Will it work ?
I was also thinking of going to the recovery console of the old server and doing an rsync to the new server, this way I copy the entire system to the new server.
But that's a bit heavy in my opinion. and I don't know Unix enough to remount discs and perform all tasks that would make the copy work.
There are actually several ways to do this. The first and by far the best is what the commenters have said. Use mysqldump to create a sql file then import it onto the other machine. If space is an issue on one of the machines you can import more directly like so: mysqldump {YOUR OPTIONS HERE} | mysql -h {NEWSERVER} -u root -p
You should do the above method if at all possible. It will work better 100% of the time when doing cross version imports. Just fix the errors you see. You may need to rewrite triggers and stored procedures if the syntax differs across versions.
If you know the danger and are ok with losing your data, you can try the following xtrabackup method:
Install xtrabackup on the older server (http://www.percona.com/software/percona-xtrabackup)
Get a full and consistent backup from xtrabackup (read the docs)
Shutdown mysql on the new server
Copy the backup from xtrabackup to that new server
Start up mysql again, it may take a while as it upgrades the tables
I have done this before across mysql server versions, BUT this is not reliable, and you quite possibly could end up with unreliable or corrupted data. Do it at your own risk.
I have an MSSQL dump file that I want to import into a MySQL database. I attempted doing so via phpMyAdmin and setting the compatibility to MSSQL but that doesn't seem to work. It consistently throws MySQL server has gone away. Upping the max_allowed_packet and wait_timeout didn't do anything to solve that either.
Is there a better way to import this database dump?
Try SQL Server Integration Services (SSIS), an ETL tool (Extract, Transform and Load) which is very much needed for the Data warehousing applications. Also SSIS is used to perform operations like loading the data based on the need, performing different transformations on the data.
Free from MS: http://msdn.microsoft.com/en-us/library/ms143731.aspx
Useful links:
http://www.codeproject.com/Articles/155829/SQL-Server-Integration-Services-SSIS-Part-1-Basics
Assuming you have dealt with all syntax incompatibilities, you can use this:
mysql -u<user> -p < db_backup.sql
If you are just scripting tables and data that should work fine. If you have GO statements in your script remove them, you don't need them for tables and inserts.
If you want to script other objects too you need to review each one as there are significant syntax differences.
I wanna reinstall windows on my PC i wanna backup my Databases in MySQL. I have around 30 plus databases. is there an easy way to back up the content and restore it later ?
You can use mysqldump -A to do generate sql dumps for all databases.
Reference: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Alternatively, you can also just copy the acutal data directory.
Edit: apologies for not being specific, as others have noted this will work only ISAM. For innodb, you'll need to backup using mysqldump or another utility such as phpMyAdmin.
Use mysqldump to create a database dump of each database. You can later easily recreate the databases from these dumps by running them through mysql. This would be the most generic answer, knowing nothing more of your set-up.
If your databases contains MyISAM tables, then you could just copy the files. Otherwise (using INNODB) this doesn't work.
I assum you don't have the binary log activated, you should use mysqldump.
Take a look at: http://dev.mysql.com/doc/refman/5.1/en/backup-methods.html
You could try with PHPMyADMIN if you don't feel confortable with mysqldump.
go to phpmyadmin and export all the database.. After installing wamp in ur new pc.. go to import and import the files you've exported previously..
Have you given the GUI tools a try?
http://dev.mysql.com/downloads/gui-tools/5.0.html
Have a look at the "Backup" option in the MySQL Administrator. The "Restore" option might also be helpful after the backup is done. :-)
Allows you to backup a single db or all db's at once.
You can use SQLyog MySQL GUI to backup your database. It has scheduled backup(you can export data into a single file or as multiple files) and backup as SQL dump(The dump will contain SQL statements to create the table and/or populate the table) to take backup and can restore those .SQL files using Execute SQL script tool.
try the tool here.
What is the prefer way to generate mysql backup while application is running ?
I want to provide functionality to admin to take backup of database at the same time when other admin using the same application from other computer.
What is the prefer way to handling this scenario ?
Hopefully you can take backup using mysqldump utility without stopping the database. Mysqlworkbench application provides easier interface to do this. If you are looking for a more advanced option and worry about transaction you can set up a replicated server, so that you can take the stable backups without stopping the master server.
if you are working on a webserver with php support use phpMyAdmin or any mySQL Dumper