What tools are you using to track changes in your MySQL database? Currently I'm in a project where we use a plain text-file (version controlled via SVN) in which we manually add SQL statements when making changes to the database.Many of the changes magically disappears every now and then, and we are now looking for a better way to change track our database.
EDIT:
One thing that I forgot to mention, we are using stored procedures and functions, so it's not only the database structure that we want to track changes on / version controll.
There is a simple solution:
Make all changes to the database schema and static data via scripts
Version control the scripts
Toad for MySQL has a great schema comparison tool
http://www.quest.com/toad-for-mysql/
I think you need something like this (I test it for Firebird and it works very well) :
http://www.upscene.com/products.audit.index.php
I thought there was a MySQL version but NO :(
for MySQL, I see just this :
http://solutions.mysql.com/solutions/partner.php?partner=1532
But if it is just for development, I think that the answer given here is good
mysql-diff compares tables, but not stored procedures yet.
Related
I'm using MODx CMS and would like to use git for co-working. However, as you know, MODx stores some of code places in database. So, I'd like to know, how to version MySQL for co-working except dumping? Thanks
You'll need to store the database in some format, and it can't be SQL as you can't just tell a live database to update the schema using a SQL file.
Basically, you'll have to store an incremental set of commands that updates the database. Git won't really help you in this case, you are going to have to use your own system.
The easiest way to achieve this is by just numbering your database versions and storing only the changes in your favorite programming language.
Step 1: store the current database version somewhere.
Step 2: store all updates to the database in files.
update/mysql_1_to_2.py
update/mysql_2_to_3.py
# etc
Step 3: create the initial database
update/mysql_0_to_1.py
If you use that system, all you need to do is keep track of the current in use version and the version that's most recent in your code. When you need to update, just run all mysql_x_to_y scripts and you're done with the versioning. mysql_0_to_1 can do the initial bootstrap and if you somehow manage to ever reach 1000 revisions, just use mysql_0_to_1000 to take a shortcut.
The system I outlined above should work really well for linear repositories, but might be a bit harder to use for trees (branches, multiple developers, etc). I'm sure you can come up with something though.
It sounds like perhaps you are talking about stored procedures and/or user-defined functions?
In any case, the best method is mysqldump - presumably, you don't need the data, just the stored procs, user-defined functions, and perhaps table structures. There are options for mysqldump to control what gets output.
If you want to add versioning of database to versioning of code, you have to see at Liquibase. To avoid repeating everything again, my older full answer on topic
I am doing an ongoing MySQL database development. I have a create database script and a set of scripts to patch it along the time. In those patch I need to check if the target database is the correct version. I am thinking to add a table to my schema for this purpose but it might overkill this problem.
I am wondering what is the best practice to do it.
THanks,
That is what I do for a number of databases - a table called schema_history, that my scripts which update the schema always add a row to: with date, version ID, purpose, etc. I can see what version any database is by looking at the last record in schema_history -- very handy.
I recommend this approach.
I am using maven plugin for that. It can track your database changes as well as apply missing SQL scripts.
https://github.com/m-szalik/dbpatch-maven-plugin
We are converting our database to MYSQL from MSSQL 2005.
Someone told me this is possible by generating a script in MSSQL using Database Publishing Wizard. I already created a script. Then by dragging it to the Query Writer in MYSQL. I am currently using SQLyog for creation of database.
How can I use that script to create a MYSQL file?
I also tried to use demo versions of converting tools but to no avail.
Please help me. =)
There is no simple or quick way to do a task like this. THe two database have differnt syntax and differnt datatypes, etc. I certainly would not trust a converting tool as you may want to make changes to fix bad design choices in SQL server to better choices in MYSQL.
Take your script and then run each section and find where it fails and then look up the correct syntax for mySQL and fix it.
Here is alink to a book you need to have for this conversion project as it wil show the syntax differnences:
http://www.amazon.com/SQL-Nutshell-OReilly-Kevin-Kline/dp/0596518846/ref=sr_1_2?s=books&ie=UTF8&qid=1330382519&sr=1-2
Is there a way to use a MYSQL database without the database management system.. Like use tables offline without installing the db management system on the machine..
If there is can you please point me in the right direction?
Thank you!
As far as I know, there is no way to do this.
However, there is a portable DBMS SQLIte. It comes in different ways and can be used on other platform with different programming languages.
After reading your comment, I'm almost sure, this is what you need.
It's not that fast as MySQL I guess, but it works.
You can use The embedded MySQL Server Library to access MySQL data files without running the MySQL server.
You can setup a database to work on your localhost. This will be offline unless you setup the front-end stuff to let the internet interact with it.
What exactly do you mean "without the database management system"? You always need a way of interacting with it, even if it is offline. (Otherwise how can it work for you?)
The server side piece of the application, mysql-server, is needed at a minumum to run mysql. This server application comes with all the tools built-in to manage the instance. I doubt you can prevent installation of this.
If you've actually opened the table files in a hex or text editor, you'll see that you will definitely need the mysql application installed to make any sense of them to use them. Sure the records are all there in plain text (.myd files for myisam, the ibdata1 file for innodb tables), but it would be a complete time-waster devising a custom app to parse or update the file structure, as well as trying to tie in table structure contained in the related files for each table.
Do you know any applications to synchronize two databases - during development sometimes it's required to add one or two table rows or new table or column.
Usually I write every sql statement in some file and during uploading path I evecute those lines on my production database (earlier backing it up).
I work with mySQL and postreSQL databases.
What is your practise and what applications helps you in that.
You asked for a tool or application answer, but what you really need is a a process answer. The underlying theme here is that you should be versioning your database DDL (and DML, when needed) and providing change scripts to be able to update any version of your database to a higher version.
This set of links provided by Jeff Atwood and written by K. Scott Allen explain in detail what this ought to look like - and they do it better than I can possibly write up here: http://www.codinghorror.com/blog/2008/02/get-your-database-under-version-control.html
For PostgreSQL you could use Another PostgreSQL Diff Tool . It can diff two SQL Dumps very fast (a few seconds on a db with about 300 tables, 50 views and 500 stored procedures). So you can find your changes easily and get a sql diff which you can execute.
From the APGDiff Page:
Another PostgreSQL Diff Tool is simple PostgreSQL diff tool that is useful for schema upgrades. The tool compares two schema dump files and creates output file that is (after some hand-made modifications) suitable for upgrade of old schema.
Have scripts (under source control of course) that you only ever add to the bottom off. That combined with regular restores from your production database to dev you should be golden. If you are strict about it, this works very well.
Otherwise I know lots of people use redgate stuff for SQLServer.
Another vote for RedGate SQL Compare
http://www.red-gate.com/products/SQL_Compare/index.htm
Wouldn't want to live without it!
Edit: Sorry, it seems this is only for SQL Server. Still - if any SQL Server users have the same question I'd definitely recommend this tool.
If you write your SQL statements for your development database (which are, I imagine, series of DDL instructions such as CREATE, ALTER and DROP), why don't you keep track of them by recording them in a table, with a "version" index? You will then be able to:
track your version changes
make a small routine allowing the "automatic" update of your production database by sending the recorded instructions to the database.
I really like the EMS tools.
There tools are available for all popular DB's and you have the same user experience for every type of DB.
One of the tools is the DB Comparer.
TOAD
saved many an ass several times in the past. Why do people run sql with no exit strategy?
the redgate one is good also.
Siebel (CRM, Sales, etc. management product) has a built-in tool to align the production database with the development one (dev2prod).
Otherwise, you've got to stick with manually executed scripts.
Navicat has a structure synchronisation wizard that handles this.
I solve this by using Hibernate. It can detect and autocreate missing tables, columns, etc.
You could add some automation to your current way of doing things by using dbDeploy or a similar script. This will allow you to keep track of your schema changes and to upgrade/rollback your schema as you see fit.
Here's a straight linux bash script I wrote for syncing Magento databases... but you can easily modify it for other uses :)
http://markshust.com/2011/09/08/syncing-magento-instance-production-development
DBV - "Database version control, made easy!" (PHP)