So, O'Reilly's ONLamp.com has published the "Top 10 MySQL Best Practices" at http://www.onlamp.com/pub/a/onlamp/2002/07/11/MySQLtips.html. Sadly, I find most "best practice" list do not thoroughly explain the "why" enough so that people can make their own decisions.
For instance, #3 is "Protect the MySQL installation directory from access by other users." I was intrigued at what they would consider the "installation" directory. By reading the tip, they actually mean the data directory. They say nothing of the log directory, nor that innodb data files may be in different places than the standard myisam data directories.
They perpetuate a myth in #4, "Don't store binary data in MySQL." What they really mean is "don't store large data in MySQL", which they go into in the tip. While it's true that there is very little benefit to having binary data in a database, they don't go into what those benefits are. This means that people can't make informed decisions, just "the best practice is this so I'm doing it."
The benefit of putting binary data in MySQL is to be able to associate metadata and other data. For instance, "user 200 owns file 483". If user 200 is gone from the system, how can you make sure file 483 is as well? There's no referential integrity unless it's in the database. While it's true that in most cases people would rather sacrifice the referential integrity for things like faster database backups and easier partitioning of large data objects, I believe in giving people full disclosure so they can make their own informed decision.
#5 is my biggest pet peeve. "Stick to ANSI SQL," with the goal being to be able to migrate to a different platform without having to rewrite the code. Does anyone tell Oracle folks not to use pl/sql like collections? Nobody says "SQL is a declarative language, pl/sql is procedural therefore you should never use it". How about SQL Server folks not to use transact-sql statements like WAITFOR? MATCH... AGAINST is not standard SQL, so I should never use it?
Now, of course, if you're selling a product to be run on different database platforms, then sure, you want to be platform agnostic. But you'd know that from the start. And if you have to migrate platforms you're going to have to do lots of work anyway, because there are third-party additions to all the software any way.
And why would *anyone* choose a specific database, and then *not* use those features? I think that it's a good tip to stick to ANSI SQL if you *know* you want to, or if you have no idea about the DBMS you're using.
If you want to see how this cripples MySQL, check out Visibone's SQL chart at: http://www.visibone.com/sql/chart_1200.jpg -- you can buy it here:
I would amend #6 by explaining how the industry standard is to use sequences, as well as data tables such as calendar tables, and that stored procedures should be built to deal with sequences. The problem with a coded solution is that it is difficult do the proper locking needed for sequences if more than one access is needed at a time. The reason I say stored procedures is that I believe that the database should handle the locking of tables, not the code, just as I believe referential integrity should be enforced at the database level. Everything else is pretty good. I had a list a while back of "SQL Best Practices" here: http://sheeri.com/archives/104. I may post later on about my own personal MySQL Best Practices....
[...] Top 10 MySQL Best
[...] Top 10 MySQL Best Practices (0 visite) [...]
The O'Reilly article is from
The O'Reilly article is from 2002, would be interesting to see what a current top 10 list would focus on.
[...] Sheeri Kritzer Cabral
[...] Sheeri Kritzer Cabral - The MySQL She-BA wrote an interesting post today on Top 10 MySQL Best PracticesHere’s a quick excerpt So, O’Reilly’s ONLamp.com has published the “Top 10 MySQL Best Practices” at http://www.onlamp.com/pub/a/onlamp/2002/07/11/MySQLtips.html. Sadly, I find most “best practice” list do not thoroughly explain the “why” enough so that people can make their own decisions. For instance, #3 is “Protect the MySQL installation directory from access by other users.” I was intrigued at what they would consider the “installation” directory. By reading the tip, they actually mean the data directory. They s [...]
The portability argument is
The portability argument is often used - both in terms of SQL, and with database abstraction layers. There are sensible arguments for it, like having customers that use different database brands. But except for that, it's really a bad idea.
It does not scale. You're building in overhead, and an app built on a specific db is not just a matter of the SQL. Some schema choices, all the way to hardware choices, are inevitably geared towards that database.
So, migrating to another db later, apart from being time-costly and headache-painful, will not be optimal given the already existent underlying infrastructure. Having the portability layer may just makes it work, but it sure doesn't make it fast.
Chances are the migrated situation will be slower. If it's faster, then the original design infrastructure was apparently not optimal for the first db. It happens (usually gets highly publicised ;-) but it often merely indicates familiarity of the designers with a particular db, not the fundamental suitability of the other dbs they tried.
Oh yeah, I totally forgot
Oh yeah, I totally forgot about that. NONONO! The MySQL user shouldn't be allowed to login at all! It should have /bin/false in the /etc/passwd or something. Dear heavens!
I wasn't terribly impressed
I wasn't terribly impressed with the list either. I agree with your points, especially about sticking to ANSI... good Lord, how many times do we have to go over that?
"For those few operations that need to happen at the file-system level, the DBA should login as the MySQL user." No. The MySQL user shouldn't be allowed to log in. That's pretty basic.