Skip to main content

Posts

Showing posts from July, 2011

MyISAM Key Buffer Usage

For MyISAM one of the most important variables is the Key Buffer.  The Key Buffer is sometimes called the Key Cache. It's used as a buffer for the indices of MyISAM tables. There is some overhead in the buffer depending on the configured key block size. The official way to calculate the key buffer usage as documented in the MySQL Reference manual: 1 - ((Key_blocks_unused * key_cache_block_size) / key_buffer_size)  This will return the factor, so you have to multiply it with 100 to get the percentage. The Key_blocks_unused is used instead of the more obvious Key_blocks_used. This is due to the fact that Key_blocks_used is the maximum number of key blocks ever used. It will not return to 0 after a FLUSH TABLES. This calculation does not take the overhead in account. The key buffer efficiency can be calculated if the key buffer is empty or (has been) completely full. If the the key buffer is full: key_buffer_coefficient = key_cache_block_size/(key_buffer_size/Key_block...

Working with IP's in MySQL and MariaDB - Part 2

Use DNS directly from your database mysql> SELECT lookup('localhost'); +---------------------+ | lookup('localhost') | +---------------------+ | 127.0.0.1 | +---------------------+ 1 row in set (0.00 sec) mysql> SELECT reverse_lookup('127.0.0.1'); +-----------------------------+ | reverse_lookup('127.0.0.1') | +-----------------------------+ | localhost | +-----------------------------+ 1 row in set (0.00 sec) This is how you install these functions. Build udf_example.so which is in your mysql source. ( make udf_example.so ) Copy the udf_example.so file from your build directory to your plugin_dir. Create the lookup and reverse_lookup functions mysql> CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so'; Query OK, 0 rows affected (0.00 sec) mysql> CREATE FUNCTION reverse_lookup RETURNS STRING SONAME 'udf_example.so'; Query OK, 0 rows affected (0.00 sec) I've created a feature ...

Working with IP's in MySQL and MariaDB

For MySQL it's a best practice to store IP addresses in a INT column rather than in a VARCHAR. This allows for more compact storage. This best practice is only for MySQL as PostgreSQL does have data types like inet and cidr . MySQL is equiped with the INET_ATON() and INET_NTOA() functions since version 3.23.15. In MySQL 5.6.3 the INET6_ATON() and INET6_NTOA() functions were addes to finaly add IPv6 address support. To make it easier to work with IPv4 and IPv6 addresses the IS_IPV4_COMPAT(), IS_IPV4_MAPPED(), IS_IPV4() and IS_IPV6() functions were added. The difference between the new and old functions is that the old functions use INT UNSIGNED to store IP addresses and the new function uses VARBINARY(16) for IPv6 addresses and VARBINARY(4) for IPv4 addresses. Here are some examples about how you could do nifty things with IP addresses in MySQL. Store hosts and networks in MySQL CREATE TABLE `hosts` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `hostname` varchar(255) DEFA...