Join the DZone community and get the full member experience.Join For Free
upgrading mysql server is a very interesting task as you can approach it with so much different “depth”. for some this is 15 minutes job for others it is many month projects. why is that ?
performing mysql upgrade two things should normally worry you. it is regressions – functionality regressions when what you’ve been using before does not work any more or works with different result and performance regressions when performance (in a broad sense) is negatively affected.
in general even minor mysql version upgrade can have both of these
issues. it gets larger as you have a larger leap in minor version –
upgrade of mysql 5.0.30 to 5.0.32 is generally likely to expose less
issues than 5.0.30 to 5.0.86. the largest amount of potential issues
happens when you upgrade to different major version, especially if you
skip over one. mysql 5.0 to 5.1 upgrade is a lot safer upgrade path
than 4.1 to 5.1 just because so much more people have followed that
so how do people approach the upgrade process ? i will describe couple of processes which i’ll call “reckless” and “safe” with no negative meaning implied
reckless approach is typically used by small simple systems or by hosting providers. this simply means stopping old mysql version and starting new one. mysql always was very good maintaining on disk binary compatibility between version and so you can run mysql 5.0 database with mysql 5.1 with no problems in most cases. when storage type changes, such as decimal field got whole another meaning in mysql 5.0 mysql generally supports legacy storage format for a while, even if it is not clearly visible. mysqlcheck -a –check-upgrade is a good quick way to check for known incompatibilities and fix them.
the data storage is however only small part of the problem – much bigger is potential behavior changes which may impact your application only subtly – some features can stop working or work differently after change. for example you may get queries returning different result or getting different execution plan, taking minutes or hours even though they were previously sub second. the changes which got a lot of publicity over years is change of timestamp output format in mysql 4.1 or changing join evaluation in 5.0 (which could both cause different result set or make query not runnable in mysql 5.0)
in case you’re using reckless approach you just hope you’re lucky – you hope you’re using simple enough functionality not to be affected or if you are you are capable of implementing fixes quickly, and what is most important your users will forgive you bugs or potential data loss you may run into
reckless approach is safest if you’re running application which uses simple mysql functionality which is unlikely to be affected. if you’re something like select name from users where id=5 you can probably go to the earliest mysql version and still get same result. the more exotic or complicated functionality is the more likely it to be changed. it is also a lot safer to use this approach if you’re using some widely used application rather than your site which exists in single installation – wordpress, vbulletin etc. with such software, if you’re not upgrading to the most bleeding edge software, chances are someone else has done it before you, and so if there are some problems they have been worked around. the more widely used and well maintained software is the more likely it is to run on wide set of mysql versions.
safe approach so what if you actually care about your user experience or at least about your data ? in this case you may need to take it much slower checking your progress along the way. there is no limit as safe you can get so i would just outline some reasonable safety for example
upgrade qa upgrade needs to start with development/qa boxes. if you’re using safe approach you probably do not do development against your production. note as soon as you upgrade qa envinronment the code which runs on it may not run well on production until it is upgraded. in case fixing code to run on different mysql version is taking a lot of time you may wish to create second qa/dev environment just for this project.
query validation it is often hard to ensure queries work same way with different mysql version, unless you have very detailed automated qa. so what you can do is get the backup of the database and get query log (you can use mk-query-digest with tcpdump to sniff out queries if you can’t enable log for any reason). as you’ve gotten database backup and set of queries which is representative enough you should set it up on 2 same boxes and use mk-upgrade tool to run comparison. the tool will run select queries on both new and old mysql installations and check result set, explain plan and execution time, reporting you on all the differences. when you can analyze the differences and see if there is anything you need to deal with.
stress testing running single stream of queries with good speed is not enough. you also need to perform stress testing to ensure both mysql does not crash under your load as well s it scales well. there have been number of scalability bugs in mysql history when issues would only happen at high load. you can do this in test/stress test envinronment or you can do it later when you setup some slaves with this version (or selecting to use version only for new shard and measuring its capacity)
setting up the slave(s) if you want to minimize downtime it is best to use mysql replication for upgrade. once you have setup slave with new version and made it to caught up you can use mk-table-checksum to ensure data is the same. it is possible some update statements worked differently in the new version or you run into some replication bug – in any case you need to take care about these if you’re to be safe. adding the slave with new version for testing is also a safe way to test things out – you can move read traffic to such slave to ensure new version stability and performance while you still have the slave running the old version in case you need to fail back quickly. this especially makes sense for cloud environments as amazon ec2 where it is easy and inexpensive to temporary get extra boxes for time of upgrade.
swapping master. finally as you have your slave running on new mysql version you want to promote it to the master and upgrade master too. i’d take the final backup before upgrading and make sure to keep binary logs for some time, in case you run into some serious issues with master. in many cases you can leave the ex-master as a slave so you can fail back to the old version easily if you need to. in other cases however it is not possible as mysql only fully support slaves newer than the master. older slaves may have issues unable to interpret new replication stream correctly. if this is the problem for you can try tungsten replicator which claims to work in both directions (though i have not tried it myself)
note in case you’re having sharded envinronment you often approach things a bit differently – upgrading one shard with full validation and when doing reckless upgrades for other shards after you’re sure your application works well with them. you can often stage upgrades in time a bit so if something happens (like mysql crashes) you have only one/few shard to deal with.
Opinions expressed by DZone contributors are their own.