<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pixelbyter &#187; MySQL</title>
	<atom:link href="http://pixelbyter.co.uk/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://pixelbyter.co.uk</link>
	<description>#rich nicholls</description>
	<lastBuildDate>Tue, 11 May 2010 11:07:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>optimising MySQL server</title>
		<link>http://pixelbyter.co.uk/2010/02/09/optimising-mysql/</link>
		<comments>http://pixelbyter.co.uk/2010/02/09/optimising-mysql/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 15:19:35 +0000</pubDate>
		<dc:creator>pixelbyter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://pixelbyter.co.uk/?p=116</guid>
		<description><![CDATA[Over the weekend the Real World web sites went down following a torrent of visitors with the imminent release of Peter Gabriel&#8217;s Scratch My Back, which played havoc on our MySQL databases and downed our websites. Our connections maxed out and started to queue, causing any pages requiring a DB connection to refuse to load. [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend the Real World web sites went down following a torrent of visitors with the imminent release of Peter Gabriel&#8217;s Scratch My Back, which played havoc on our MySQL databases and downed our websites. Our connections maxed out and started to queue, causing any pages requiring a DB connection to refuse to load. After spending the weekend altering MySQL&#8217;s settings the average number of simultaneous connections on our MySQL database dropped from 100 to about 2 thanks to the vastly increased speed at which queries are now running. Here&#8217;s the top 3 things that were changed to speed things up (keep in mind, our web server currently runs both MySQL and Apache with 8GB RAM):</p>
<h3>query_cache_size</h3>
<p>The MySQL query cache will cache the result sets of your queries, serving them instead of executing the same queries again. According to MySQL, &ldquo;<a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache.html">Searches for a single row in a single-row table are 238% faster with the query cache than without it.</a>&rdquo; For a query to return a cached result it must match the cached query exactly, in terms of case and whitespace, and it must not contain subqueries (read this article about <a href="http://dev.mysql.com/doc/refman/5.1/en/rewriting-subqueries.html">Rewriting Subqueries as Joins</a>). This is disabled by default in MySQL, so be sure to enable it first. I set it to 64MB.</p>
<pre name="code">
query-cache-type = 1
query_cache_size = 64M
</pre>
<h3>key_buffer_size / innodb_buffer_pool_size</h3>
<p>The key buffer size is the amount of memory allocated to store table indexes, which can considerably speed up a query as searching for which rows to retrieve may require no disk access. innodb_buffer_pool_size is the innoDB implementation of this setting. On dedicated MySQL servers it is recommended to set this to 75% of the amount of RAM installed. I set key_buffer_size to 256MB as we have few MyISAM tables, and innodb_buffer_pool_size to 1GB so Apache and other services were not adversely affected.</p>
<pre name="code">
key_buffer_size = 256M
innodb_buffer_pool_size = 1G
</pre>
<h3>table_cache</h3>
<p>The table cache is the number of tables that will be stored in memory at once, each table being stored in the cache as MySQL accesses it. I set it to 256.</p>
<pre name="code">
table_cache = 256
</pre>
<h3>helpful apps</h3>
<p>MySQL Report will return information on how your server is currently performing and a list of some of the more useful variables. <a href="http://hackmysql.com/mysqlreport">Get MySQL Report here</a>, and <a href="http://hackmysql.com/mysqlreportguide">get a guide to understand the report here</a>.</p>
<p>MySQL Tuner will analyse your server and provide recommendations as to how different MySQL settings could be altered and any problems that could result from the current configuration. <a href="http://blog.mysqltuner.com/download/">Get MySQL Tuner here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://pixelbyter.co.uk/2010/02/09/optimising-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysqldump database backup for mixed InnoDB and MyISAM tables</title>
		<link>http://pixelbyter.co.uk/2010/01/22/mysqldump-database-backup-for-mixed-innodb-and-myisam-tables/</link>
		<comments>http://pixelbyter.co.uk/2010/01/22/mysqldump-database-backup-for-mixed-innodb-and-myisam-tables/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 11:55:53 +0000</pubDate>
		<dc:creator>pixelbyter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://pixelbyter.local/?p=44</guid>
		<description><![CDATA[Backing up a collection of MyISAM and InnoDB tables within a database via mysqldump can cause problems. MyISAM tables require locking, whereas InnoDB tables need to remain unlocked and can also take advantage of single transactions to speed up the backup process. I decided to write the following PHP script to list all of the [...]]]></description>
			<content:encoded><![CDATA[<p>Backing up a collection of MyISAM and InnoDB tables within a database via mysqldump can cause problems. MyISAM tables require locking, whereas InnoDB tables need to remain unlocked and can also take advantage of single transactions to speed up the backup process. I decided to write the following <strong>PHP</strong> script to list all of the databases and tables that the supplied user has permissions to view, which automatically uses the correct mysqldump settings for MyISAM and InnoDB table types, saving each table&#8217;s data to a separate SQL file. In the event of a connection error during the mysqldump of a table, the mysqldump command is repeated until it completes successfully.</p>
<pre name="code" class="php">
$user = 'YOUR_USER';
$password = 'YOUR_PASSWORD';
$host = 'YOUR_HOST';
$backup_dir = '/path_to_backup_dir/'.date('YmdHis');

//mysqldump commands
$default_mysqldump_shared_command = 'mysqldump --force --user='.$user.' --password='.$password.' --host='.$host.' --quote-names --default-character-set=utf8 --verbose --compress';
$default_mysqldump_innodb_command = $default_mysqldump_shared_command.' --single-transaction --skip-add-locks --skip-lock-tables';
$default_mysqldump_myisam_command = $default_mysqldump_shared_command.' --opt';

//connect
set_time_limit(0);
if(!mysql_connect($host, $user, $password))
	exit;

//create backup dir
shell_exec('mkdir '.$backup_dir);

//cycle through databases
$query = "SHOW DATABASES";
$database_result = mysql_query($query);
while($database_data = mysql_fetch_array($database_result, MYSQL_ASSOC)) {
	//current db
	$current_database = $database_data['Database'];

	//create dir
	echo shell_exec('mkdir '.$backup_dir.'/'.$current_database);

	//get table list
	mysql_select_db($current_database);
	$query = "SHOW FULL TABLES WHERE Table_Type != 'VIEW'";
	$table_result = mysql_query($query);
	while($table_data = mysql_fetch_array($table_result, MYSQL_ASSOC)) {
		//current table
		$current_table = $table_data['Tables_in_'.$current_database];

		//get table type
		$query = "SHOW TABLE STATUS LIKE '{$current_table}'";
		$table_properties_result = mysql_query($query);
		$table_properties = mysql_fetch_array($table_properties_result, MYSQL_ASSOC);

		echo 'backing up '.$current_database.'.'.$current_table."\r\n";
		$success = false;
		while($success == false) {
			//innodb or not?
			if($table_properties['Engine'] == 'InnoDB')
				$result = shell_exec($default_mysqldump_innodb_command.' '.$current_database.' '.$current_table.'| gzip &gt; '.$backup_dir.'/'.$current_database.'/'.$current_table.'.gz')."\r\n";
			else
				$result = shell_exec($default_mysqldump_myisam_command.' '.$current_database.' '.$current_table.'| gzip &gt; '.$backup_dir.'/'.$current_database.'/'.$current_table.'.gz')."\r\n";

			//error
			if(strpos($result, 'Error 2013') !== false)
				echo 'lost connection, trying again'."\r\n";
			else
				$success = true;
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://pixelbyter.co.uk/2010/01/22/mysqldump-database-backup-for-mixed-innodb-and-myisam-tables/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
