<?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>MySQL Preacher &#187; OS</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/category/os/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>A MySQL blog, from a MySQL DBA</description>
	<lastBuildDate>Wed, 16 Jun 2010 13:13:15 +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>Automating MySQL access with expect and bash scripting</title>
		<link>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 17:08:26 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=327</guid>
		<description><![CDATA[If you have multiple database servers with strange names, or if you have to hop over multiple machines to connect to any mysql database server, then you know what a pain it can be to administer such a setup. Thanks to some scripting, you can automate such tasks as follows:
Create an expect script:
/path/to/sshmysql.exp
#!/usr/bin/expect -f
#script by [...]]]></description>
			<content:encoded><![CDATA[<p>If you have multiple database servers with strange names, or if you have to hop over multiple machines to connect to any mysql database server, then you know what a pain it can be to administer such a setup. Thanks to some scripting, you can automate such tasks as follows:</p>
<p>Create an expect script:<br />
/path/to/sshmysql.exp</p>
<blockquote><p>#!/usr/bin/expect -f<br />
#script by darren cassar<br />
#mysqlpreacher.com</p>
<p>set machine  [lindex $argv 0]</p>
<p>set timeout -1</p>
<p>spawn ssh username@$machine<br />
match_max 100000<br />
expect -exact &#8220;assword: &#8221;<br />
send &#8212; &#8220;password\r&#8221;<br />
send &#8212; &#8220;sudo -k; sudo su &#8211; mysql\r&#8221;<br />
expect -exact &#8220;sudo -k; sudo su &#8211; mysql&#8221;<br />
expect -exact &#8220;assword:&#8221;<br />
send &#8212; &#8220;password\r&#8221;<br />
interact</p></blockquote>
<p># you should change the word password in &#8217;send &#8212; &#8220;password\r&#8221;&#8216; to your login password<br />
# if you have the same password for each environment you could also script logging into mysql directly from the same expect script BUT that is not recommended.</p>
<p>Create a bash script:<br />
/path/to/login.sh</p>
<blockquote><p>#!/bin/bash<br />
#script by darren cassar<br />
#mysqlpreacher.com</p>
<p>sm=&#8217;/path/to/sshmysql.exp&#8217;</p>
<p>menu() {<br />
  echo &#8221; 101 &#8211; dev.databaseserver1 &#8221;<br />
  echo &#8221; 102 &#8211; dev.databaseserver2 &#8221;<br />
  echo &#8221; 103 &#8211; dev.databaseserver3 &#8221;<br />
  echo &#8221; 201 &#8211; qa.databaseserver1 &#8221;<br />
  echo &#8221; 301 &#8211; uat.databaseserver1 &#8221;<br />
  echo &#8221; 302 &#8211; uat.databaseserver2 &#8221;<br />
  echo &#8221; 401 &#8211; prod.databaseserver1 &#8221;<br />
  echo &#8221; &#8221;<br />
}</p>
<p>ARGUMENT=notmenu</p>
<p>if [ -z "$1" ]<br />
  then<br />
    ARGUMENT=menu<br />
else<br />
  choice=$1<br />
fi</p>
<p>if [ $ARGUMENT = "menu" ]<br />
  then<br />
    menu<br />
else<br />
  case &#8220;$choice&#8221; in<br />
  101|dev.databaseserver1   ) $sm dev.databaseserver1;;<br />
  102|dev.databaseserver2   ) $sm dev.databaseserver2;;<br />
  103|dev.databaseserver3   ) $sm dev.databaseserver3;;<br />
  201|qa.databaseserver1   ) $sm qa.databaseserver1;;<br />
  301|uat.databaseserver1   ) $sm uat.databaseserver1;;<br />
  302|uat.databaseserver2   ) $sm uat.databaseserver2;;<br />
  401|prod.databaseserver1   ) $sm prod.databaseserver1;;<br />
  *        ) echo &#8220;Wrong value passed to script&#8221;<br />
             menu ;;<br />
  esac<br />
fi</p></blockquote>
<blockquote><p>alias l=&#8217;/path/to/login.sh&#8217;</p></blockquote>
<p>Output: </p>
<blockquote><p>[darrencassar@mymachine ~ ]$ l<br />
 101 &#8211; dev.databaseserver1<br />
 102 &#8211; dev.databaseserver2<br />
 103 &#8211; dev.databaseserver3<br />
 201 &#8211; qa.databaseserver1<br />
 301 &#8211; uat.databaseserver1<br />
 302 &#8211; uat.databaseserver2<br />
 401 &#8211; prod.databaseserver1</p></blockquote>
<p>Output:<br />
The below command would log you into the first development database server as mysql user.</p>
<blockquote><p>[darrencassar@mymachine ~ ]$ l 101 </p></blockquote>
<p>On each machine place aliases for each instance in the .profile</p>
<blockquote><p>alias use3306=&#8217;mysql -u root -p -h 127.0.0.1 -P 3306 &#8211;prompt=&#8221;mysql \D> &#8220;&#8216;</p></blockquote>
<p>The above setup can be used using any client/server OS: Linux, Solaris, MAC OS or Windows(running Cygwin)</p>
<p><strong>NOTE: If you store the password in clear text inside the expect script, you should at least save the scripts inside an encrypted partition on your machine and make sure that folder is not shared or accessible by anyone. Another way of doing it would be to use either SSHKeys OR save the password inside a file and encrypt it using <a href="http://www.madboa.com/geek/openssl/#encrypt-simple" target="_blank">OpenSSL</a></strong></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Make Mac Finder sort folders on top</title>
		<link>http://mysqlpreacher.com/wordpress/2009/12/make-mac-finder-sort-folders-on-top/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/12/make-mac-finder-sort-folders-on-top/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 10:28:41 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Finder]]></category>
		<category><![CDATA[folders]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=322</guid>
		<description><![CDATA[Once every so often something bugs me enough to look up and here is today&#8217;s bugger! Sorting files and folders in Mac&#8217;s Finder by type, folders first!
In essence:
1. Select Finder, click on Go from the menu bar and select Go to Folder
2. From the dialog box that opens, type:
/System/Library/CoreServices/
and press Return
3. Locate Finder application, right [...]]]></description>
			<content:encoded><![CDATA[<p>Once every so often something bugs me enough to look up and here is today&#8217;s bugger! Sorting files and folders in Mac&#8217;s Finder by type, folders first!</p>
<p>In essence:<br />
1. Select Finder, click on Go from the menu bar and select Go to Folder<br />
2. From the dialog box that opens, type:<br />
/System/Library/CoreServices/<br />
and press Return<br />
3. Locate Finder application, right click on it, and select Show Package Contents<br />
4. Navigate to Contents>Resources>English.lproj and open InfoPlist.strings in a text editor<br />
5. Navigate to the line which says<br />
&#8220;Folder&#8221; = &#8220;Folder&#8221;;<br />
at around line 7 of the file, and simply add an empty space or a symbol (such as &#8220;.&#8221; or &#8220;~&#8221;) in front of the second &#8220;Folder&#8221;.<br />
6. Save the text file, type in the Administrator password when asked, and close the text file.<br />
7. The final step would be to restart finder, which you can achieve by holding in the ALT or OPTION key and right clicking on the Finder icon in Dock, then selecting Relaunch.</p>
<p>Full detailed tutorial can be found <a href="http://forum.notebookreview.com/showthread.php?t=208068">here</a>: thanks to &#8220;Budding&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/12/make-mac-finder-sort-folders-on-top/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; IP vs DNS</title>
		<link>http://mysqlpreacher.com/wordpress/2009/12/mysql-ip-vs-dns/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/12/mysql-ip-vs-dns/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 15:39:12 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[grants]]></category>
		<category><![CDATA[hosts]]></category>
		<category><![CDATA[skip-name-resolve]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=315</guid>
		<description><![CDATA[A MySQL is running happily on a machine situated in a land far far away. I grant access to a user@machine_aaaaaa (grant select on db.* to &#8216;user&#8217;@'machine_aaaaa&#8217; identified by &#8216;password&#8217;; flush privileges;), send an email to the user saying it should run fine and happily go off my way. Mistake!
It seems this user can&#8217;t connect [...]]]></description>
			<content:encoded><![CDATA[<p>A MySQL is running happily on a machine situated in a land far far away. I grant access to a user@machine_aaaaaa (grant select on db.* to &#8216;user&#8217;@'machine_aaaaa&#8217; identified by &#8216;password&#8217;; flush privileges;), send an email to the user saying it should run fine and happily go off my way. Mistake!</p>
<p>It seems this user can&#8217;t connect to the mysql gets access denied:<br />
Access denied for user &#8216;user&#8217;@'machine_bbbbb&#8217; (using password: YES)</p>
<p>Note that the machine the user is being seen from is totally different from the one I set up in the grant!! WHY?</p>
<p>run a reverse lookup on the ip of machine_aaaaa, turns out it shows machine_bbbbb. So I figure a big bad guy messed up /etc/hosts, I was right! `cat /etc/hosts` just to find an entry for machine_aaaaa blehh</p>
<p>Ok, solution is to remove the entry from /etc/hosts (after finding out it wasn&#8217;t even necessary and wasn&#8217;t even supposed to be there in the first place), restart nscd.</p>
<p>Retry<br />
AGAIN &#8211; Access denied for user &#8216;user&#8217;@'machine_bbbbb&#8217; (using password: YES)</p>
<p>What the &#8230;.</p>
<p>What&#8217;s wrong now? &#8212; yeah silly me forgot to `flush hosts` :) </p>
<p>Retry<br />
YOHOO I&#8217;m in!</p>
<p>I&#8217;ve seen quite a few blogs about disabling name resolve in mysql with skip-name-resolve and granting privileges using IPs &#8211; something which would also have avoided the above (but still not found the root of the problem):</p>
<p><a href="http://jeremy.zawodny.com/blog/archives/011421.html">http://jeremy.zawodny.com/blog/archives/011421.html</a><br />
<a href="http://www.mysqlperformanceblog.com/2008/05/31/dns-achilles-heel-mysql-installation/">http://www.mysqlperformanceblog.com/2008/05/31/dns-achilles-heel-mysql-installation/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/12/mysql-ip-vs-dns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Circular Replication Implementation / Testing using MySQL Sandbox</title>
		<link>http://mysqlpreacher.com/wordpress/2009/01/mysql-sandbox-circular-replication-implementation-testing/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/01/mysql-sandbox-circular-replication-implementation-testing/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 16:11:15 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[circular replication]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[sandbox]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=66</guid>
		<description><![CDATA[This is a simple mysql circular replication implementation on a single machine (just a proof of concept) which can easily be done on a broader scale. Just be aware of the cons of circular replication which mainly gets down to: once a node freaks out or stops for one reason or the other, it&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple mysql circular replication implementation on a single machine (just a proof of concept) which can easily be done on a broader scale. Just be aware of the cons of circular replication which mainly gets down to: once a node freaks out or stops for one reason or the other, it&#8217;s a bitch and you need to take care of IMMEDIATELY.</p>
<p>Download Sandbox from https://launchpad.net/mysql-sandbox/+download<br />
Download MySQL from http://dev.mysql.com/downloads</p>
<p>Copy the downloaded software onto the your *nix box onto any folder of your preference called $BASEDIR</p>
<p>run:</p>
<p>cd /$BASEDIR</p>
<p>gunzip mysql_sandbox_X.X.XX.tar.gz<br />
tar -xf mysql_sandbox_X.X.XX.tar</p>
<p>ln -s mysql_sandbox_X.X.XX sandbox</p>
<p>time /$BASEDIR/sandbox/make_replication_sandbox &#8211;circular=4 &#8211;topology=circular /$BASEDIR/mysql-5.1.30-linux-x86_64-glibc23.tar.gz</p>
<blockquote><p><code><br />
user@hostname $ time /$BASEDIR/sandbox/make_replication_sandbox --circular=4 --topology=circular /$BASEDIR/mysql-5.1.30-linux-x86_64-glibc23.tar.gz<br />
installing node 1<br />
installing node 2<br />
installing node 3<br />
installing node 4<br />
# server: 1:<br />
# server: 2:<br />
# server: 3:<br />
# server: 4:<br />
# server: 1:<br />
# server: 2:<br />
# server: 3:<br />
# server: 4:<br />
Circular replication activated<br />
group directory installed on /$BASEDIR/sandboxes/rcsandbox_5_1_30<br />
</code><code><br />
real    1m47.913s<br />
user    0m6.364s<br />
sys     0m2.445s<br />
</code><code><br />
cd /$BASEDIR/sandboxes/rcsandbox_5_1_30<br />
</code><code><br />
user@hostname $ ./n1<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 9<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node1 [localhost] {msandbox} ((none)) &gt; show databases;<br />
+--------------------+<br />
| Database           |<br />
+--------------------+<br />
| information_schema |<br />
| mysql              |<br />
| test               |<br />
+--------------------+<br />
3 rows in set (0.01 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} ((none)) &gt; show variables like 'port';<br />
+---------------+-------+<br />
| Variable_name | Value |<br />
+---------------+-------+<br />
| port          | 17001 |<br />
+---------------+-------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} ((none)) &gt; exit<br />
Bye<br />
user@hostname $ ./n2<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 9<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node2 [localhost] {msandbox} ((none)) &gt; show variables like 'port';<br />
+---------------+-------+<br />
| Variable_name | Value |<br />
+---------------+-------+<br />
| port          | 17002 |<br />
+---------------+-------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node2 [localhost] {msandbox} ((none)) &gt; exit<br />
Bye<br />
user@hostname $ ./n3<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 9<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node3 [localhost] {msandbox} ((none)) &gt; show variables like 'port';<br />
+---------------+-------+<br />
| Variable_name | Value |<br />
+---------------+-------+<br />
| port          | 17003 |<br />
+---------------+-------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node3 [localhost] {msandbox} ((none)) &gt; exit<br />
Bye<br />
user@hostname $ ./n4<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 8<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node4 [localhost] {msandbox} ((none)) &gt; show variables like 'port';<br />
+---------------+-------+<br />
| Variable_name | Value |<br />
+---------------+-------+<br />
| port          | 17004 |<br />
+---------------+-------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} ((none)) &gt; exit<br />
Bye<br />
</code><code><br />
user@hostname $ cd ..<br />
user@hostname $ ./n1<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 10<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node1 [localhost] {msandbox} ((none)) &gt; show databases;<br />
+--------------------+<br />
| Database           |<br />
+--------------------+<br />
| information_schema |<br />
| mysql              |<br />
| test               |<br />
+--------------------+<br />
3 rows in set (0.00 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} ((none)) &gt; create database dba;<br />
Query OK, 1 row affected (0.04 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} ((none)) &gt; USE dba;<br />
Database changed<br />
node1 [localhost] {msandbox} (dba) &gt; CREATE TABLE `instance` (<br />
-&gt; `dbid` tinyint unsigned NOT NULL,<br />
-&gt; `hostname` varchar(255) NOT NULL,<br />
-&gt; `port` smallint unsigned NOT NULL,<br />
-&gt; PRIMARY KEY (`dbid`)<br />
-&gt; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
Query OK, 0 rows affected (0.03 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} (dba) &gt; CREATE TABLE `backups` (<br />
-&gt; `instance` tinyint unsigned NOT NULL,<br />
-&gt; `dbname` varchar(255) NOT NULL,<br />
-&gt; `date_time` datetime NOT NULL,<br />
-&gt; `dumpsize` varchar(16) NOT NULL,<br />
-&gt; `checksum` varchar(20) NOT NULL,<br />
-&gt; FOREIGN KEY (instance) REFERENCES instance(dbid) ON UPDATE CASCADE ON DELETE RESTRICT<br />
-&gt; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
Query OK, 0 rows affected (0.02 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} (dba) &gt; CREATE TABLE `table_size` (<br />
-&gt; `instance` tinyint unsigned NOT NULL,<br />
-&gt; `dbname` varchar(255) NOT NULL,<br />
-&gt; `tbname` varchar(255) NOT NULL,<br />
-&gt; `size_of_data` decimal(18,0) NOT NULL,<br />
-&gt; `size_of_index` decimal(18,0) NOT NULL,<br />
-&gt; `total` decimal(18,0) NOT NULL,<br />
-&gt; `date_time` datetime NOT NULL,<br />
-&gt; FOREIGN KEY (instance) REFERENCES instance(dbid) ON UPDATE CASCADE ON DELETE RESTRICT<br />
-&gt; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
Query OK, 0 rows affected (0.01 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} (dba) &gt; CREATE TABLE `memory` (<br />
-&gt; `instance` tinyint unsigned NOT NULL,<br />
-&gt; `date_time` datetime NOT NULL,<br />
-&gt; `size` decimal(18,0) NOT NULL,<br />
-&gt; `rss` decimal(18,0) NOT NULL,<br />
-&gt; FOREIGN KEY (instance) REFERENCES instance(dbid) ON UPDATE CASCADE ON DELETE RESTRICT<br />
-&gt; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
Query OK, 0 rows affected (0.01 sec)<br />
</code><code><br />
node1 [localhost] {msandbox} (dba) &gt; exit<br />
Bye<br />
user@hostname $ ./n4<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 9<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node4 [localhost] {msandbox} ((none)) &gt; use dba;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A<br />
</code><code><br />
Database changed<br />
node4 [localhost] {msandbox} (dba) &gt; CREATE TABLE `connectivity` (<br />
-&gt; `instance` tinyint unsigned NOT NULL,<br />
-&gt; `date_time` datetime NOT NULL,<br />
-&gt; `established` smallint unsigned NOT NULL,<br />
-&gt; `listen` smallint unsigned NOT NULL,<br />
-&gt; `close` smallint unsigned NOT NULL,<br />
-&gt; `time_wait` smallint unsigned NOT NULL,<br />
-&gt; FOREIGN KEY (instance) REFERENCES instance(dbid) ON UPDATE CASCADE ON DELETE RESTRICT<br />
-&gt; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
Query OK, 0 rows affected (0.01 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; show tables;<br />
+---------------+<br />
| Tables_in_dba |<br />
+---------------+<br />
| backups       |<br />
| connectivity  |<br />
| instance      |<br />
| memory        |<br />
| table_size    |<br />
+---------------+<br />
5 rows in set (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; select * from memory;<br />
Empty set (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; show create table memory;<br />
+--------+---------------------------------------------------------+<br />
| Table  | Create Table                                                                                                                                                                                                                                                                                                                                    |<br />
+--------+---------------------------------------------------------+<br />
| memory | CREATE TABLE `memory` (<br />
`instance` tinyint(3) unsigned NOT NULL,<br />
`date_time` datetime NOT NULL,<br />
`size` decimal(18,0) NOT NULL,<br />
`rss` decimal(18,0) NOT NULL,<br />
KEY `instance` (`instance`),<br />
CONSTRAINT `memory_ibfk_1` FOREIGN KEY (`instance`) REFERENCES `instance` (`dbid`) ON UPDATE CASCADE<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |<br />
+--------+---------------------------------------------------------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; insert into instance (dbid,hostname,port) values ('1','machine1','17001');<br />
Query OK, 1 row affected (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; select * from instance;<br />
+------+----------+-------+<br />
| dbid | hostname | port  |<br />
+------+----------+-------+<br />
|    1 | machine1 | 17001 |<br />
+------+----------+-------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; insert into memory (instance,date_time,size,rss) values('1',now(),'42252431','2543234');<br />
Query OK, 1 row affected (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; select * from memory;<br />
+----------+---------------------+----------+---------+<br />
| instance | date_time           | size     | rss     |<br />
+----------+---------------------+----------+---------+<br />
|        1 | 2009-01-28 16:27:00 | 42252431 | 2543234 |<br />
+----------+---------------------+----------+---------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node4 [localhost] {msandbox} (dba) &gt; exit<br />
Bye<br />
user@hostname $ ./n2<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 10<br />
Server version: 5.1.30-log MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
node2 [localhost] {msandbox} ((none)) &gt; use dba;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A<br />
</code><code><br />
Database changed<br />
node2 [localhost] {msandbox} (dba) &gt; select * from memory;<br />
+----------+---------------------+----------+---------+<br />
| instance | date_time           | size     | rss     |<br />
+----------+---------------------+----------+---------+<br />
|        1 | 2009-01-28 16:27:00 | 42252431 | 2543234 |<br />
+----------+---------------------+----------+---------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
node2 [localhost] {msandbox} (dba) &gt; show tables;<br />
+---------------+<br />
| Tables_in_dba |<br />
+---------------+<br />
| backups       |<br />
| connectivity  |<br />
| instance      |<br />
| memory        |<br />
| table_size    |<br />
+---------------+<br />
5 rows in set (0.00 sec)<br />
</code><code><br />
node2 [localhost] {msandbox} (dba) &gt; exit<br />
Bye<br />
user@hostname $ ./check_slaves<br />
node # 1<br />
Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
node # 2<br />
Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
node # 3<br />
Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
node # 4<br />
Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes<br />
</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/01/mysql-sandbox-circular-replication-implementation-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Installing: Binary tarball (.tar.gz) *nix based platforms</title>
		<link>http://mysqlpreacher.com/wordpress/2009/01/mysql-installing-binary-tarball-targz-nix-based-platforms/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/01/mysql-installing-binary-tarball-targz-nix-based-platforms/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 23:38:20 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[securing]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=50</guid>
		<description><![CDATA[Installing MySQL is quite an easy thing to do, especially when done using pkgs, dmgs or exes. It gets just a tad more time consuming and brain intensive when installing a .tar.gz binary package. It is when you&#8217;re compiling MySQL source directly that you&#8217;ll need some planning and playing, but the latter is only done [...]]]></description>
			<content:encoded><![CDATA[<p>Installing MySQL is quite an easy thing to do, especially when done using pkgs, dmgs or exes. It gets just a tad more time consuming and brain intensive when installing a .tar.gz binary package. It is when you&#8217;re compiling MySQL source directly that you&#8217;ll need some planning and playing, but the latter is only done in particular cases such as when you&#8217;ll need a particular engine not shipped with a pre-compiled package etc.</p>
<p>Today we&#8217;re going through the steps required for a typical MySQL installation from a .tar.gz package on a *nix based platform, including the download, installation, configuration and securing.</p>
<p>Steps involved:<br />
1. Download MySQL binary tarball from mysql.com<br />
2. Create a folder structure where the installation will be held.<br />
3. Install the package<br />
4. Secure the installation</p>
<p>Step 1: Download MySQL</p>
<p>Go to http://dev.mysql.com/downloads/ and choose the particular version that suits your platform (OS and machine type). Do note that installing a 32 bit version of MySQL on a 64 bit machine will not give you the full power available. There is quite a bit of performance impact when going for 64 bit, so if possible install the 64 bit version.</p>
<p>Step 2: Set up a folder structure to hold the MySQL related files</p>
<p>Normally in any database server I like to create a /mysql which will be holding any MySQL related info including, the releases, installation, configuration, data, logs etc. The below is a just personal choice and is subject to your liking. A typical folder structure would be</p>
<p>/mysql/ -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applications -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maatkit<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sandbox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySQL books<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RefMans<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;installations -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_cnf -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_master_malta_3306<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_slave_malta_3406<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_data -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_master_malta_3306<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_slave_malta_3406</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_dist -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_inst -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_logs -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;releases -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5.0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5.1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6.0</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;testing -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perl<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sandbox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scripts<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc</p>
<p>Step 3: Installing MySQL</p>
<p>The installation part takes just a few standard commands which follow:</p>
<p>#Execute the following only if you don&#8217;t already have a mysql user and mysql group. If you are not sure run: `cat /etc/group | grep -i mysql` and `cat /etc/group | grep -i mysql`. The &#8216;grep -i&#8217; permits you to find just the user mysql or variant of it including those of a different case.</p>
<blockquote><p><code>mysqlpreacher:~ darrencassar$ cat /etc/group | grep -i mysql<br />
_mysql:*:74:<br />
mysqlpreacher:~ darrencassar$ cat /etc/passwd | grep -i mysql<br />
_mysql:*:74:74:MySQL Server:/var/empty:/usr/bin/false</code></p></blockquote>
<p>#groupadd mysql<br />
#useradd -g mysql mysql</p>
<p>#Let&#8217;s assume you followed the above folder structure</p>
<p>cd /mysql/releases/5.1<br />
ls<br />
gunzip mysql-5.1.xx-xxx-xx.tar.gz<br />
tar -xf mysql-5.1.xx-xxx-xx.tar<br />
ls</p>
<blockquote><p><code>mysqlpreacher:~ darrencassar$ cd /mysql/releases/5.1/<br />
mysqlpreacher:5.1 darrencassar$ ls<br />
5.1.26                    mysql-5.1.26-rc-osx10.5-x86_64.dmg    mysql-5.1.28-rc-osx10.5-x86.tar.gz<br />
5.1.28                    mysql-5.1.26-rc-osx10.5-x86_64.tar.gz    mysql-5.1.30-osx10.5-x86_64.tar.gz<br />
mysqlpreacher:5.1 darrencassar$ gunzip mysql-5.1.30-osx10.5-x86_64.tar.gz<br />
mysqlpreacher:5.1 darrencassar$ tar -xf mysql-5.1.30-osx10.5-x86_64.tar<br />
mysqlpreacher:5.1 darrencassar$ ls<br />
5.1.26                    mysql-5.1.26-rc-osx10.5-x86_64.dmg    mysql-5.1.28-rc-osx10.5-x86.tar.gz    mysql-5.1.30-osx10.5-x86_64.tar<br />
5.1.28                    mysql-5.1.26-rc-osx10.5-x86_64.tar.gz    mysql-5.1.30-osx10.5-x86_64</code></p></blockquote>
<p>mv mysql-5.1.xx-xxx-xx ../../installations/mysql_inst/<br />
cd /mysql/installations/mysql_inst/<br />
mv mysql-5.1.xx-xxx-xx mysql-5.1.xx-xxx-xx_001</p>
<blockquote><p><code>mysqlpreacher:5.1 darrencassar$ mv mysql-5.1.30-osx10.5-x86_64 ../../installations/mysql_inst/<br />
mysqlpreacher:5.1 darrencassar$ cd /mysql/installations/mysql_inst/<br />
mysqlpreacher:mysql_inst darrencassar$ mv mysql-5.1.30-osx10.5-x86_64 mysql-5.1.30-osx10.5-x86_64_001</code></p></blockquote>
<p>#set up your naming convention, this is a way I find useful to work with myself<br />
ln -s mysql-5.1.xx-xxx-xx_001 mysql_51xx_001<br />
cd mysql_51xx_001</p>
<blockquote><p><code>mysqlpreacher:mysql_inst darrencassar$ ln -s mysql-5.1.30-osx10.5-x86_64_001 mysql_5130_001<br />
mysqlpreacher:mysql_inst darrencassar$ cd mysql_5130_001</code></p></blockquote>
<p>#set ownerships and permissions<br />
sudo chown -R mysql .<br />
sudo chgrp -R mysql .</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ sudo chown -R mysql .<br />
mysqlpreacher:mysql_5130_001 darrencassar$ sudo chgrp -R mysql .</code></p></blockquote>
<p>#Install the MySQL using mysql_install_db<br />
sudo scripts/mysql_install_db &#8211;user=mysql</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ sudo scripts/mysql_install_db --user=mysql<br />
WARNING: The host 'mysqlpreacher' could not be looked up with resolveip.<br />
This probably means that your libc libraries are not 100 % compatible<br />
with this binary MySQL version. The MySQL daemon, mysqld, should work<br />
normally with the exception that host name resolving will not work.<br />
This means that you should use IP addresses instead of hostnames<br />
when specifying MySQL privileges !<br />
Installing MySQL system tables...<br />
OK<br />
Filling help tables...<br />
OK<br />
</code><code><br />
To start mysqld at boot time you have to copy<br />
support-files/mysql.server to the right place for your system<br />
</code><code><br />
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !<br />
To do so, start the server, then issue the following commands:<br />
</code><code><br />
./bin/mysqladmin -u root password 'new-password'<br />
./bin/mysqladmin -u root -h mysqlpreacher password 'new-password'<br />
</code><code><br />
Alternatively you can run:<br />
./bin/mysql_secure_installation<br />
</code><code><br />
which will also give you the option of removing the test<br />
databases and anonymous user created by default.  This is<br />
strongly recommended for production servers.<br />
</code><code><br />
See the manual for more instructions.<br />
</code><code><br />
You can start the MySQL daemon with:<br />
cd . ; ./bin/mysqld_safe &amp;<br />
</code><code><br />
You can test the MySQL daemon with mysql-test-run.pl<br />
cd ./mysql-test ; perl mysql-test-run.pl<br />
</code><code><br />
Please report any problems with the ./bin/mysqlbug script!<br />
</code><code><br />
The latest information about MySQL is available at http://www.mysql.com/<br />
Support MySQL by buying support/licenses from http://shop.mysql.com/</code></p></blockquote>
<p>sudo chown -R root .<br />
sudo chown -R mysql data</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ sudo chown -R root .<br />
mysqlpreacher:mysql_5130_001 darrencassar$ sudo chown -R mysql data</code></p></blockquote>
<p>#provide a link from the data folder onto the mysql_data folder<br />
cd /mysql/installations/mysql_data/<br />
ln -s  /mysql/installations/mysql_inst/mysql_51xx_001/data/ data_51xx_001</p>
<p>cd /mysql/installations/mysql_inst/mysql_51xx_001/<br />
sudo su</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ cd /mysql/installations/mysql_data/<br />
mysqlpreacher:mysql_data darrencassar$ ln -s /mysql/installations/mysql_inst/mysql_5130_001/data/ data_5130_001<br />
mysqlpreacher:mysql_data darrencassar$ cd /mysql/installations/mysql_inst/mysql_5130_001<br />
mysqlpreacher:mysql_5130_001 darrencassar$ mkdir /mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/<br />
mysqlpreacher:mysql_5130_001 darrencassar$ cp -rp support-files/my-small.cnf /mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf<br />
mysqlpreacher:mysql_5130_001 darrencassar$ sudo su<br />
Password:<br />
sh-3.2# pwd<br />
/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001</code></p></blockquote>
<p>#Depending upon the size of your dataset, a generic my.cnf to use (options file where you set specific parameters which are read by MySQL before starting up) can be obtained from the support-files folder. This file normally requires quite some tweaking depending on the hardware, dataset, type of application querying the database, etc. Configuration is not a one time task either since things change with time, and so must the parameters set in this file.</p>
<p>#The generic samples of my.cnf are:<br />
my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf</p>
<p>#Unless the location of the options file described above is hardcoded in the startup script (mysql.server), the order by which MySQL looks for a my.cnf is:</p>
<p>Filename                            Purpose</p>
<p>/etc/my.cnf                       Options<br />
/etc/mysql/my.cnf            Global options (as of MySQL 5.1.15)<br />
SYSCONFDIR/my.cnf          Global options<br />
$MYSQL_HOME/my.cnf      Server-specific options<br />
defaults-extra-file             The file specified with &#8211;defaults-extra-file=path, if any<br />
~/.my.cnf                          User-specific options</p>
<p>#Once the installation is complete, just start MySQL using:<br />
sudo bin/mysqld_safe  &#8211;defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf &#8211;user=mysql &amp;<br />
#note that the &#8211;defaults-file needs to be the first parameter in this command otherwise you&#8217;ll see an error “Too many arguments (first extra is &#8216;–defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf&#8217;).”</p>
<p>#you can check if MySQL did indeed start using the following<br />
ps -ef | grep -i mysql</p>
<blockquote><p><code>sh-3.2# sudo bin/mysqld_safe  --defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf --user=mysql &amp;<br />
[1] 88880<br />
sh-3.2# 090105 03:19:09 mysqld_safe Logging to '/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data/mysqlpreacher.err'.<br />
090105 03:19:09 mysqld_safe Starting mysqld daemon with databases from /mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data<br />
</code><code><br />
sh-3.2# ps -ef | grep -i mysql<br />
0 88880 88282   0   0:00.02 ttys001    0:00.04 /bin/sh bin/mysqld_safe --defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf --user=mysql<br />
74 88992 88880   0   0:00.04 ttys001    0:00.12 /mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/bin/mysqld --defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf --basedir=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001 --datadir=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data --user=mysql --log-error=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data/mysqlpreacher.err --pid-file=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data/mysqlpreacher.pid --socket=/tmp/mysql.sock --port=3306<br />
0 89007 88282   0   0:00.00 ttys001    0:00.00 grep -i mysql</code></p></blockquote>
<p>Step 4: Secure the installation</p>
<p>When a database is placed online it does require some careful securing since it would otherwise be vulnerable to malicious acts such as alterations and denial of service.</p>
<p>MySQL uses Access Controlled Lists in order to discriminate between users, that means each user is given access to perform certain tasks while prohibited from doing others. It is quite flexible but managing fine grained rights allocation to a lot of users can also become quite a nightmare (consult maatkit mk_show_grants at http://www.maatkit.org/doc/mk-show-grants.html for this kind of setup). A MySQL command helpful in the latter task is:<br />
SHOW GRANTS FOR &#8216;user&#8217;@'host&#8217;;</p>
<p>Using GRANT and REVOKE will permit you to set privileges for individual users e.g.<br />
In order to grant select to john on database FOO while connected via localhost, the command would be:<br />
GRANT SELECT ON FOO.* TO &#8216;john&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;password&#8217;;<br />
FLUSH PRIVILEGES;</p>
<p>Note that omitting the &#8216;identified by&#8217; would cause a user to have access without a password, something which should never be permitted for an online live server.</p>
<p>A further security measure, apart from ACL described above is to place MySQL server behind a firewall, preferably inside a DMZ (demilitarized zone) and should the MySQL server be accessible only through the socket file, then it would be a good idea to insert &#8217;skip-networking&#8217; in the configuration file my.cnf thus disabling any client from accessing the instance from any machine other than the machine on which it is installed.</p>
<p>One last suggestion as regards the security topic, consult MySQL updates and security patches in case there is something which directly impacts your current setup so that you can upgrade immediately if you are vulnerable in any way.</p>
<p>#access MySQL directly can be done using<br />
bin/mysql -u root -p<br />
SHOW DATABASES;</p>
<p>#If running a live MySQL system, run `drop database test`, you can always execute `create database test` later</p>
<p>#Create a password for root<br />
USE MYSQL;</p>
<p>UPDATE user<br />
SET Password = PASSWORD(&#8220;password&#8221;)<br />
WHERE User=&#8217;root&#8217;;</p>
<p>FLUSH PRIVILEGES;<br />
EXIT</p>
<p>#checking MySQL password set earlier<br />
bin/mysql -u root -p #don&#8217;t insert a password to test it out<br />
bin/mysql -u root -p #&#8230;. insert the new password (“password” in our case)</p>
<p>#It is good practice to set up a monitoring script which queries MySQL for any user without a password or for anonymous users.</p>
<p>USE MYSQL;<br />
SELECT User, Host, Password<br />
FROM user<br />
WHERE User=&#8221; OR Host=&#8221; OR Password=&#8221;;</p>
<p>#This should be remedied using:<br />
DELETE FROM user<br />
WHERE User=&#8221;;</p>
<blockquote><p><code>sh-3.2# bin/mysql -u root -p<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 1<br />
Server version: 5.1.30 MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
mysql&gt; SHOW DATABASES;<br />
+--------------------+<br />
| Database           |<br />
+--------------------+<br />
| information_schema |<br />
| mysql              |<br />
| test               |<br />
+--------------------+<br />
3 rows in set (0.02 sec)<br />
</code><code><br />
mysql&gt; USE MYSQL;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A<br />
</code><code><br />
Database changed<br />
mysql&gt; UPDATE user<br />
-&gt; SET Password = PASSWORD("password")<br />
-&gt; WHERE User='root';<br />
Query OK, 3 rows affected (0.04 sec)<br />
Rows matched: 3  Changed: 3  Warnings: 0<br />
</code><code><br />
mysql&gt; FLUSH PRIVILEGES;<br />
Query OK, 0 rows affected (0.02 sec)<br />
</code><code><br />
mysql&gt; EXIT<br />
Bye<br />
sh-3.2# bin/mysql -u root -p<br />
Enter password:<br />
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<br />
sh-3.2# bin/mysql -u root -p<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 3<br />
Server version: 5.1.30 MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
mysql&gt; USE MYSQL;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A<br />
</code><code><br />
Database changed<br />
mysql&gt; SELECT User, Host, Password<br />
-&gt; FROM user<br />
-&gt; WHERE User='' OR Host='' OR Password='';<br />
+------+---------------+----------+<br />
| User | Host          | Password |<br />
+------+---------------+----------+<br />
|      | localhost     |          |<br />
|      | mysqlpreacher |          |<br />
+------+---------------+----------+<br />
2 rows in set (0.00 sec)<br />
</code><code><br />
mysql&gt; DELETE FROM user<br />
-&gt; WHERE User='';<br />
Query OK, 2 rows affected (0.02 sec)<br />
</code><code><br />
mysql&gt; SELECT User, Host, Password<br />
-&gt; FROM user<br />
-&gt; WHERE User='' OR Host='' OR Password='';<br />
Empty set (0.00 sec)<br />
</code><code><br />
mysql&gt; \q<br />
Bye<br />
sh-3.2#</code></p></blockquote>
<p>This section does not exhaust all security guidelines of course, but helps making your instance more secure.</p>
<p>#DONE</p>
<p>&#8212;&#8212;&#8212;&#8211; o &#8212;&#8212;&#8212;&#8211;</p>
<p>#A few general notes:</p>
<p>#Note that not all the MySQL commands need a &#8216;;&#8217; at the end, an example is `\s` and `SHOW STATUS \G`<br />
#Exiting from MySQL can be done using `EXIT` or `QUIT` or `\q`<br />
#A helpful command to get you started is `?` which provides a list of commands available</p>
<p>#There are many other commands and combination of syntaxes which you can write in order to obtain results</p>
<p>#It is good practice to insert MySQL path in the env variable PATH in order to avoid typing the whole path each time you want to use MySQL. In bash you&#8217;d do:</p>
<p>export PATH=/path/to/mysql/bin:$PATH</p>
<p>o insert the MySQL&#8217;s path before all the others, otherwise just interchange the positions of $PATH and the actual /path/to/mysql/bin</p>
<p>#Killing the MySQL is done using the following command:<br />
bin/mysqladmin -u root -p shutdown</p>
<p>#Starting and stopping MySQL automatically can be done using mysql.server, found in support-files folder. The file needs to be copied in /etc/rc.d and edited to insert the custom parameters of data directory, base directory etc.</p>
<p>#If the storage engine used is innodb, a good my.cnf option would be innodb_file_per_table since otherwise innodb will store all it&#8217;s table data in a single file which is not optimal when having big tables which need to be optimzed / analyzed.</p>
<p>#Remember to set up monitoring scripts should this be a live system in order to avoid downtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/01/mysql-installing-binary-tarball-targz-nix-based-platforms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
