Have you tried MySQLTuner yet? It's free and it makes optimizing your MySQL server easier than ever!

I’ll be taking a short break from posting, but I should be back underway within week!  Here’s what I’m working on during the break:

  • MySQLTuner - Thank you for all of the e-mails with suggestions, patches and complaints. The 1.0 version of MySQLTuner is in the works and I hope that it helps you get more done with your MySQL server.
  • Boxcheck - A new version of boxcheck.com is coming and it will include more tests for you to use. Also, the tests that it already has will be more reliable. I might even throw in a little AJAX to get everyone excited.
  • PleskHacker - I’m still working on the Plesk database documentation, but this project is a lower priority than the first two.

I’m moving into a new house over the weekend, so please don’t be discouraged if you e-mail me and you don’t receive a quick response. For all of the fans of Twitter out there, you can find me on Twitter as RackerHacker.

Comments No Comments »

Normally, qmail will be able to process the mail queue without any interaction from the system administrator, however, if you want to force it to process everything that is in the queue right now, you can do so:

kill -ALRM `pgrep qmail-send`

If for some peculiar reason you don’t have pgrep on your server, you can go about it a slightly different way:

kill -ALRM `ps ax | grep qmail-send | grep -v grep | awk '{print $1}'`

Your logs should begin filling up with data about e-mails rolling through the queue.

Comments No Comments »

Upgrading Plesk from 7.5.x to 8.x will change your Plesk-related MySQL tables from MyISAM to InnoDB. This allows for better concurrency in the Plesk panel when a lot of users are logged in simultaneously. However, some server administrators will disable InnoDB support in MySQL to save resources. This will cause problems after the upgrade.

Plesk may display an error on a white page that looks something like:

Cannot initialize InnoDB

This could mean that InnoDB support was disabled when MySQL was started. To correct this issue, search through the /etc/my.cnf for this line:

skip-innodb

If you find it in your configuration, remove it, and then restart MySQL. To test that InnoDB is enabled, you can refresh the Plesk page, or you can log into MySQL and run SHOW ENGINES. The output from the SHOW ENGINES statement should show YES on the line with InnoDB.

Should DISABLED appear instead, you may have an issue with your InnoDB configuration in your /etc/my.cnf. Be sure to check for innodb_data_file_path and make sure that it is set to an appropriate value.

A value of NO is not a good sign. This means that your version of MySQL was compiled without InnoDB support. This means that it cannot be enabled at runtime because MySQL wasn’t built with any support for InnoDB. Be sure to recompile MySQL with --with-innodb or obtain a new package for your operating system which includes InnoDB support.

If you suspect that your MySQL InnoDB configuration is incorrect, you may want to review this documentation on MySQL’s site:

For MySQL 5: 13.2.3. InnoDB Configuration
For MySQL 4/3.23: 13.2.4. InnoDB Configuration

Comments No Comments »

After running the idea by some of my fellow technical folks, I’ve considered making an array of screencasts aimed to prepare people for the MySQL DBA exam. I haven’t decided to make them free or charge for them as of yet, but if I did charge a fee, it would be much less than getting the training from MySQL ($2,499USD in most locations).

So, I have two questions for the general techy community:

1. What tools/applications would you recommend on a Mac for making high-quality screencasts that have a professional feel?

2. Would you pay for these screencasts (if they are really good), and if so, how much would you want to spend in total to get all of the screencasts for the DBA certification?

Feel free to add comments to this post, or you’re welcome to drop me an e-mail at major at mhtx dot net. Your feedback is greatly appreciated!

Comments 1 Comment »

I finally remembered this book when someone asked me about how to get started with PHP and MySQL development. If you get the chance, get a copy of this book:

PHP and MySQL Web Development by Luke Welling, Laura Thomson
Barnes & Noble: http://snurl.com/265xp

Why do I like this book so much?

  • Teaching by application - The book teaches fundamentals by showing how to apply techniques to an active website. There’s not a ton of theory to wade through, and you feel like you’re learning the material faster.
  • Intertwined strategies - You learn how to get PHP working with MySQL, and then you learn how to optimize your code. It’s important to know which work is best done by PHP and which is best done by MySQL. This book teaches both.
  • Lots of examples - The CD-ROM comes with tons of code examples that actually relate to something you can use.

I’d be happy to loan my copy, but I’ve loaned it out and it never returned.

Comments No Comments »

I’ve just upgraded RackerHacker to Wordpress 2.5.1. If you haven’t upgraded your own blog installation yet, I’d recommend doing so soon!

Download It
Upgrade It

Comments No Comments »

Call me weird - but I like to know where people host their sites. When I get a link to a nice-looking site, I’ll get there and think, “Hmm, I wonder where they host.”

Part of this curiosity probably stems from being a server administrator. I’ve used seven different dedicated server providers before along with 5 different VPS providers. There’s quite a few shared hosters thrown into the mix as well. I like to know which companies that people use when they have a site that is tremendously vital to their everyday lives.

Without further ado, here’s some of the politicians’ hosters that I’ve found (in alphabetical order):

Bob Barr - Rackspace (67.192.188.81)
Hillary Clinton - Rackspace (72.32.103.48)
John Edwards - Internap (70.42.42.155)
Rudy Giuliani - Core NAP (64.20.231.77)
Mike Gravel - Media Temple (64.13.237.176)
Mike Huckabee - HostMySite (208.112.83.62)
Alan Keyes - ThePlanet (74.52.145.91)
John McCain - Smartech Corporation (64.203.107.147)
Ralph Nader - FutureQuest (69.5.9.21)
Barack Obama - Pair Networks (66.39.143.229)
Ron Paul - Rackspace (74.205.22.51)
Bill Richardson - Engine Yard (65.74.179.43)
Mitt Romney - Rackspace (72.32.175.83)

Comments No Comments »

It’s always been a bit of a challenge to disable TRACE and TRACK methods with Plesk. The only available options were to create a ton of vhost.conf files or adjust the httpd.include files and prevent modifications with chattr (which is a bad idea on many levels).

Luckily, Parallels has made things easier with a new knowledge base article.

Comments 1 Comment »

Before getting started, it’s important to understand why MySQL uses locks. In short - MySQL uses locks to prevent multiple clients from corrupting data due to simultaneous writes while also protecting clients from reading partially-written data.

Some of you may be thinking, “Okay, this makes sense.” If that’s you, skip the next two paragraphs. If not, keep reading.

Analogies can help understand topics like these. Here’s one that I came up with during a training class. Consider two people sitting in front of a notepad on a table. Let’s say that a sentence like “The quick brown fox jumps over the lazy dog” is already written on the notepad. If both people want to read the sentence simultaneously, they can do so without getting in each other’s way. A third or fourth person could show up and they could all read it at the same time.

Well, let’s say one of the people at the table is writing a screenplay for Cujo, and they want to change “lazy” to “crazy”. That person erases the “l” in “lazy” and then adds a “cr” to the front to spell “crazy”. So if the other person is reading the sentence while the first person is writing, they will see “lazy” turn into “azy”, then “c_azy”, and then finally, “crazy”. This isn’t a big issue in real life, but on the database level, this could be dangerous. If the person who was reading the sentence showed up during the middle of the letter changes, they would think that the dog was “azy”, and they’d walk away wondering what the adjective “azy” means. To get around this, MySQL uses locking to block clients from reading data while it’s being written and it blocks clients from writing data simultaneously.

Now that we’re all familiar with what locks are, and why MySQL uses them, let’s talk about some ways to reduce the delays caused by locking. Here’s some situations you might be running up against:

Writes are delayed because reads have locked the tables
This is the most common occurrence from the servers that I have seen. When you run a SHOW PROCESSLIST, you may see a few reads at the top of the queue that are in the status of “Copying to tmp table” and/or “Sending data”. On optimized servers running optimized queries, these should clear out quickly. If you’re finding that they are not clearing out quickly, try the following:

  • Use EXPLAIN on your queries to be sure that they are optimized
  • Add indexes to tables that you query often
  • Reduce the amount of rows that are being returned per query
  • Upgrade the networking equipment between web and database servers (if applicable)
  • Consider faster hardware with larger amounts of RAM
  • Use MySQLTuner to check your current server’s configuration for issues
  • Consider moving to InnoDB to utilize row-based locking

Reads and writes are delayed because writes have locked the tables
Situations like these are a little different. There’s two main factors to consider here: either MySQL cannot write data to the disk fast enough, or your write queries (or tables) are not optimized. If you suspect a hardware issue, check your iowait with sar and see if it stays at about 10-20% or higher during the day. If it does, slow hardware may be the culprit. Try moving to SCSI disks and be sure to use RAID 5 or 10 for additional reliability and speed. SAN or DAS units may also help due to higher throughput and more disk spindles.

If you already have state-of-the-art hardware, be sure that your tables and queries are optimized. Run OPTIMIZE TABLES regularly if your data changes often to defragment the tables and clear out any holes from removed or updated data. Slow UPDATE queries suggest that you are updating too many rows, or you may be using a column in the WHERE clause that is not indexed. If you do a large amount of INSERT queries, use this syntax to enter multiple rows simultaneously:

INSERT INTO table (col1,col2) VALUES ('a','1'), ('b','2'), ('c','3');

This syntax tells MySQL to hold off on updating indexes until the entire query is complete. If you are updating a very large amount of rows, and you need to use multiple queries to avoid reaching the max_allowed_packet directive, you can do something like this:

ALTER TABLE table DISABLE KEYS;
INSERT INTO table (col1,col2) VALUES ('a','1'), ('b','2'), ('c','3');
~~~ many more inserts ~~~
ALTER TABLE table ENABLE KEYS;

This forces MySQL to not calculate any new index information until you re-enable the keys or run OPTIMIZE TABLE. If all of this does not help, consider using InnoDB as your storage engine. You can benefit from the row-level locking, which reduces locking in mixed read/write scenarios. In addition, InnoDB is able to write data much more efficiently than MyISAM.

Comments 2 Comments »

If you’re working in Plesk and you receive this error:

mchk: Unable to initialize quota settings for someuser@somedomain.com

Run this command to fix the issue, but be patient:

find /var/qmail/mailnames -type d -name '.*' ! -name '.spamassassin' -ls -exec touch '{}'/maildirfolder \; -exec chown popuser:popuser '{}'/maildirfolder \;

Thanks to Mike Jackson for this one.

Comments No Comments »