<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-12233913</id><updated>2012-01-20T12:12:46.087-08:00</updated><category term='phpbb poster_ip convert ip'/><category term='phpbb_posts'/><title type='text'>MySQL Tips</title><subtitle type='html'>Snippets of MySQL tips, solutions, examples, tutorials, and even benchmarks</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>35</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-12233913.post-5177581355893112688</id><published>2009-01-02T11:31:00.000-08:00</published><updated>2011-01-01T01:26:51.489-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='phpbb poster_ip convert ip'/><category scheme='http://www.blogger.com/atom/ns#' term='phpbb_posts'/><title type='text'>PHPBB Convert poster_ip to real IP address in phpbb_posts table</title><content type='html'>Let's say you see an offending user on your website and you have their IP and you'd like to see if they're a registered poster on your PHPBB forum.  The problem is that the poster_ip field in the phpbb_posts table is encoded.  Here's an example to convert it back and search for an offending IP, let's say in this case it's 255.255.255.255:&lt;br /&gt;&lt;br /&gt;SELECT * from nuke_phpbb_posts  where inet_ntoa(conv(poster_ip, 16, 10)) = '255.255.255.255';&lt;br /&gt;&lt;br /&gt;SELECT u.username from nuke_phpbb_posts p, nuke_phpbb_users u where inet_ntoa(conv(p.poster_ip, 16, 10)) = '207.200.116.10' and p.poster_id = u.user_id limit 1;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-5177581355893112688?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/5177581355893112688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/5177581355893112688'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2009/01/phpbb-convert-posterip-to-real-ip.html' title='PHPBB Convert poster_ip to real IP address in phpbb_posts table'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111602920031944538</id><published>2005-05-13T17:06:00.000-07:00</published><updated>2005-05-13T17:06:40.323-07:00</updated><title type='text'>ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key</title><content type='html'>If in Mysql get the message "ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key" when trying to drop a primary key, then do the following:&lt;br /&gt;&lt;br /&gt;(let's say the table is 'your_table' and the primary key column w/ auto_increment is 'the_column'):&lt;br /&gt;&lt;br /&gt;alter table your_table change the_column the_column int unsigned;&lt;br /&gt;&lt;br /&gt;to remove the auto_increment, then do a:&lt;br /&gt;&lt;br /&gt;alter table your_table drop primary key;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111602920031944538?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111602920031944538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111602920031944538' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111602920031944538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111602920031944538'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/05/error-1075-42000-incorrect-table.html' title='ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111464742040937131</id><published>2005-04-27T17:13:00.000-07:00</published><updated>2005-04-27T17:18:09.260-07:00</updated><title type='text'>How to show warning messages for LOAD DATA INFILE</title><content type='html'>Ever wondered what the warning messages were when you did a load data infile in MySQL? Well in MySQL 4.1.0 and greater you can by issuing a "SHOW WARNINGS" command at the mysql console- e.g.&lt;br /&gt;&lt;br /&gt;mydb1707&gt;load data infile '/tmp/people.txt'&lt;br /&gt;   -&gt; into table webapps.merchants&lt;br /&gt;   -&gt; fields terminated by '\t'&lt;br /&gt;   -&gt; lines terminated by '\n'&lt;br /&gt;   -&gt; ignore 1 lines;&lt;br /&gt;&lt;br /&gt;Query OK, 103 rows affected, 14 warnings (0.06 sec)&lt;br /&gt;Records: 103  Deleted: 0  Skipped: 0  Warnings: 14&lt;br /&gt;&lt;br /&gt;mydb1707&gt;show warnings;&lt;br /&gt;+---------+------+----------------------------------------------+&lt;br /&gt;| Level   | Code | Message                                      |&lt;br /&gt;+---------+------+----------------------------------------------+&lt;br /&gt;| Warning | 1265 | Data truncated for column 'state' at row 13  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 13  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'state' at row 14  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'state' at row 52  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 59  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 60  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 61  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'state' at row 71  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 72  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 78  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 82  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 86  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'state' at row 92  |&lt;br /&gt;| Warning | 1265 | Data truncated for column 'phone' at row 100 |&lt;br /&gt;+---------+------+----------------------------------------------+&lt;br /&gt;14 rows in set (0.02 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Check out http://dev.mysql.com/doc/mysql/en/show-warnings.html for the full details.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111464742040937131?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://dev.mysql.com/doc/mysql/en/show-warnings.html' title='How to show warning messages for LOAD DATA INFILE'/><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111464742040937131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111464742040937131' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111464742040937131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111464742040937131'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/how-to-show-warning-messages-for-load.html' title='How to show warning messages for LOAD DATA INFILE'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373620487973215</id><published>2005-04-17T04:09:00.000-07:00</published><updated>2005-04-17T04:10:04.880-07:00</updated><title type='text'>MySQL difference between dates in number of days</title><content type='html'>To get a date difference in days in Mysql version before 4.1 (where you can use the datediff() function instead), do the following to calculate date difference:&lt;br /&gt;&lt;br /&gt;select (TO_DAYS(date1)-TO_DAYS(date2))&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373620487973215?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373620487973215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373620487973215' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373620487973215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373620487973215'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-difference-between-dates-in.html' title='MySQL difference between dates in number of days'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373616001785062</id><published>2005-04-17T04:08:00.001-07:00</published><updated>2005-04-17T04:09:20.016-07:00</updated><title type='text'>MySQL get last 24 hours example SQL</title><content type='html'>select count(*) as cnt from log where date &gt;= DATE_SUB(CURDATE(),INTERVAL 1 DAY);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373616001785062?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373616001785062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373616001785062' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373616001785062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373616001785062'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-get-last-24-hours-example-sql.html' title='MySQL get last 24 hours example SQL'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373611044196636</id><published>2005-04-17T04:08:00.000-07:00</published><updated>2005-04-17T04:08:30.443-07:00</updated><title type='text'>Alter table auto_increment examples</title><content type='html'>ALTER TABLE tbl_name AUTO_INCREMENT = 100&lt;br /&gt;will start your records at 100&lt;br /&gt;&lt;br /&gt;ALTER TABLE tbl_name AUTO_INCREMENT = 1000&lt;br /&gt;will start your records at 1000&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373611044196636?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373611044196636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373611044196636' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373611044196636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373611044196636'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/alter-table-autoincrement-examples.html' title='Alter table auto_increment examples'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373511670642669</id><published>2005-04-17T03:51:00.000-07:00</published><updated>2005-04-17T03:51:56.706-07:00</updated><title type='text'>Resolving ERROR 1075: Incorrect table definition; There can only be one auto column and it must be defined as a key</title><content type='html'>mysql&gt; alter table test add orig_order int unsigned auto_increment;&lt;br /&gt;ERROR 1075: Incorrect table definition; There can only be one auto column and it must be defined as a key&lt;br /&gt;mysql&gt; alter table test add orig_order int unsigned auto_increment, add key(orig_order);&lt;br /&gt;Query OK, 1221 rows affected (0.10 sec)&lt;br /&gt;Records: 1221  Duplicates: 0  Warnings: 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373511670642669?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373511670642669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373511670642669' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373511670642669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373511670642669'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/resolving-error-1075-incorrect-table.html' title='Resolving ERROR 1075: Incorrect table definition; There can only be one auto column and it must be defined as a key'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373507089545819</id><published>2005-04-17T03:50:00.000-07:00</published><updated>2005-04-17T03:51:10.896-07:00</updated><title type='text'>Export a table in mysql to a file in csv format example</title><content type='html'>select * into outfile '/tmp/zips.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'&lt;br /&gt;LINES TERMINATED BY '\n'&lt;br /&gt;from zips;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373507089545819?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373507089545819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373507089545819' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373507089545819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373507089545819'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/export-table-in-mysql-to-file-in-csv.html' title='Export a table in mysql to a file in csv format example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373501065294006</id><published>2005-04-17T03:49:00.001-07:00</published><updated>2005-04-17T03:50:10.653-07:00</updated><title type='text'>MySQL find last digit = number example SQL</title><content type='html'>select address from $db.$table&lt;br /&gt;where ascii(right(address, 1)) &gt;= 48 and ascii(right(address, 1)) &lt;= 57&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373501065294006?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373501065294006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373501065294006' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373501065294006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373501065294006'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-find-last-digit-number-example.html' title='MySQL find last digit = number example SQL'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373497876173704</id><published>2005-04-17T03:49:00.000-07:00</published><updated>2005-04-17T03:49:38.760-07:00</updated><title type='text'>MySQL find duplicate repords example</title><content type='html'>select address, count(address) as cnt&lt;br /&gt;from mailing_list&lt;br /&gt;group by address&lt;br /&gt;having cnt &gt; 1&lt;br /&gt;order by cnt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373497876173704?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373497876173704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373497876173704' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373497876173704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373497876173704'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-find-duplicate-repords-example.html' title='MySQL find duplicate repords example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373489340812013</id><published>2005-04-17T03:47:00.000-07:00</published><updated>2005-04-17T03:48:13.413-07:00</updated><title type='text'>MySQL benchmark (ran 2005-08-17)</title><content type='html'>MySQL Benchmark&lt;br /&gt;Hardware: AMD Athlon64 3000+ 512MB software raid-0 on 2 WDD 120 gig HDD (partition RAID)&lt;br /&gt;my.cnf as follows:&lt;br /&gt;&lt;br /&gt;[mysqld]&lt;br /&gt;#datadir=/var/lib/mysql&lt;br /&gt;#socket=/var/lib/mysql/mysql.sock&lt;br /&gt;set-variable    = key_buffer_size=32M&lt;br /&gt;set-variable    = join_buffer_size=32M&lt;br /&gt;set-variable    = max_allowed_packet=2M&lt;br /&gt;set-variable    = table_cache=256K&lt;br /&gt;set-variable    = sort_buffer_size=24M&lt;br /&gt;set-variable    = net_buffer_length=256K&lt;br /&gt;set-variable    = myisam_sort_buffer_size=8M&lt;br /&gt;set-variable    = read_buffer_size=4M&lt;br /&gt;set-variable    = long_query_time=5&lt;br /&gt;set-variable    = thread_cache_size=1M&lt;br /&gt;set-variable    = read_rnd_buffer_size=8M&lt;br /&gt;set-variable    = tmp_table_size=256M&lt;br /&gt;set-variable    = record_buffer=1M&lt;br /&gt;set-variable    = log-slow-queries=/var/log/mysql_slow_queries.log&lt;br /&gt;set-variable    = long_query_time=3&lt;br /&gt;set-variable    = query_cache_type=1&lt;br /&gt;set-variable    = query_cache_size=32M&lt;br /&gt;set-variable    = query_cache_limit=4M&lt;br /&gt;set-variable    = max_connections=200&lt;br /&gt;skip-innodb&lt;br /&gt;&lt;br /&gt;[mysql]&lt;br /&gt;prompt="\\d\\R\\m&gt;"&lt;br /&gt;&lt;br /&gt;[mysql.server]&lt;br /&gt;user=mysql&lt;br /&gt;basedir=/var/lib&lt;br /&gt;&lt;br /&gt;[safe_mysqld]&lt;br /&gt;#err-log=/var/log/mysqld.log&lt;br /&gt;#pid-file=/var/run/mysqld/mysqld.pid&lt;br /&gt;&lt;br /&gt;[root@localhost sql-bench]# perl run-all-tests&lt;br /&gt;Benchmark DBD suite: 2.15&lt;br /&gt;Date of test:        2004-08-17 14:04:30&lt;br /&gt;Running tests on:    Linux 2.6.7-1.478 x86_64&lt;br /&gt;Arguments:&lt;br /&gt;Comments:&lt;br /&gt;Limits from:&lt;br /&gt;Server version:      MySQL 4.1.3 beta standard log&lt;br /&gt;Optimization:        None&lt;br /&gt;Hardware:&lt;br /&gt;&lt;br /&gt;alter-table:&lt;br /&gt;Total time: 20 wallclock secs ( 0.04 usr  0.02 sys +  0.00 cusr  0.00 csys =  0.06 CPU)&lt;br /&gt;ATIS: Total time:  6 wallclock secs ( 4.16 usr  0.83 sys +  0.00 cusr  0.00 csys =  4.99 CPU)&lt;br /&gt;big-tables: Total time:  7 wallclock secs ( 1.89 usr  1.58 sys +  0.00 cusr  0.00 csys =  3.47 CPU)&lt;br /&gt;connect: Total time: 80 wallclock secs (23.86 usr 10.12 sys +  0.00 cusr  0.00 csys = 33.98 CPU)&lt;br /&gt;create: Total time: 108 wallclock secs ( 1.21 usr  0.41 sys +  0.00 cusr  0.00 csys =  1.62 CPU)&lt;br /&gt;insert:&lt;br /&gt;&lt;br /&gt;Total time: 1277 wallclock secs (279.28 usr 49.60 sys +  0.00 cusr  0.00 csys = 328.88 CPU)&lt;br /&gt;select: Total time: 56 wallclock secs (21.93 usr  3.56 sys +  0.00 cusr  0.00 csys = 25.49 CPU)&lt;br /&gt;transactions: Test skipped because the database doesn't support transactions&lt;br /&gt;wisconsin: Total time:  4 wallclock secs ( 1.63 usr  0.43 sys +  0.00 cusr  0.00 csys =  2.06 CPU)&lt;br /&gt;&lt;br /&gt;All 9 test executed successfully&lt;br /&gt;&lt;br /&gt;Totals per operation:&lt;br /&gt;Operation             seconds     usr     sys     cpu   tests&lt;br /&gt;alter_table_add                        8.00    0.01    0.00    0.01     100&lt;br /&gt;alter_table_drop                       9.00    0.02    0.00    0.02      91&lt;br /&gt;connect                                5.00    2.63    0.52    3.15   10000&lt;br /&gt;connect+select_1_row                   8.00    3.69    0.75    4.44   10000&lt;br /&gt;connect+select_simple                  6.00    3.19    0.66    3.85   10000&lt;br /&gt;count                                  7.00    0.03    0.01    0.04     100&lt;br /&gt;count_distinct                         0.00    0.08    0.01    0.09    1000&lt;br /&gt;count_distinct_2                       0.00    0.09    0.01    0.10    1000&lt;br /&gt;count_distinct_big                     5.00    3.75    0.75    4.50     120&lt;br /&gt;count_distinct_group                   1.00    0.48    0.08    0.56    1000&lt;br /&gt;count_distinct_group_on_key            1.00    0.11    0.02    0.13    1000&lt;br /&gt;count_distinct_group_on_key_parts      0.00    0.46    0.07    0.53    1000&lt;br /&gt;count_distinct_key_prefix              0.00    0.09    0.02    0.11    1000&lt;br /&gt;count_group_on_key_parts               0.00    0.45    0.08    0.53    1000&lt;br /&gt;count_on_key                          12.00    3.95    0.54    4.49   50100&lt;br /&gt;create+drop                           29.00    0.15    0.03    0.18   10000&lt;br /&gt;create_MANY_tables                    21.00    0.03    0.00    0.03   10000&lt;br /&gt;create_index                           2.00    0.00    0.00    0.00       8&lt;br /&gt;create_key+drop                       31.00    0.18    0.11    0.29   10000&lt;br /&gt;create_table                           0.00    0.00    0.00    0.00      31&lt;br /&gt;delete_all_many_keys                  32.00    0.01    0.00    0.01       1&lt;br /&gt;delete_big                             0.00    0.00    0.00    0.00       1&lt;br /&gt;delete_big_many_keys                  32.00    0.01    0.00    0.01     128&lt;br /&gt;delete_key                             1.00    0.15    0.09    0.24   10000&lt;br /&gt;delete_range                           3.00    0.00    0.00    0.00      12&lt;br /&gt;drop_index                             1.00    0.00    0.00    0.00       8&lt;br /&gt;drop_table                             0.00    0.00    0.00    0.00      28&lt;br /&gt;drop_table_when_MANY_tables            3.00    0.16    0.09    0.25   10000&lt;br /&gt;insert                                31.00    5.14    2.84    7.98  350768&lt;br /&gt;insert_duplicates                      8.00    1.58    0.84    2.42  100000&lt;br /&gt;insert_key                            39.00    3.00    1.16    4.16  100000&lt;br /&gt;insert_many_fields                     3.00    0.21    0.06    0.27    2000&lt;br /&gt;insert_select_1_key                    2.00    0.00    0.00    0.00       1&lt;br /&gt;insert_select_2_keys                   3.00    0.00    0.00    0.00       1&lt;br /&gt;min_max                                2.00    0.02    0.00    0.02      60&lt;br /&gt;min_max_on_key                        17.00    7.10    0.99    8.09   85000&lt;br /&gt;multiple_value_insert                  2.00    0.20    0.03    0.23  100000&lt;br /&gt;once_prepared_select                  16.00    3.43    1.38    4.81  100000&lt;br /&gt;order_by_big                          14.00   10.84    2.38   13.22      10&lt;br /&gt;order_by_big_key                      16.00   11.15    2.41   13.56      10&lt;br /&gt;order_by_big_key2                     13.00   10.78    2.39   13.17      10&lt;br /&gt;order_by_big_key_desc                 16.00   11.22    2.44   13.66      10&lt;br /&gt;order_by_big_key_diff                 14.00   10.95    2.35   13.30      10&lt;br /&gt;order_by_big_key_prefix               14.00   10.86    2.26   13.12      10&lt;br /&gt;order_by_key2_diff                     2.00    0.97    0.18    1.15     500&lt;br /&gt;order_by_key_prefix                    1.00    0.53    0.10    0.63     500&lt;br /&gt;order_by_range                         2.00    0.61    0.09    0.70     500&lt;br /&gt;outer_join                             1.00    0.00    0.00    0.00      10&lt;br /&gt;outer_join_found                       1.00    0.00    0.00    0.00      10&lt;br /&gt;outer_join_not_found                   1.00    0.00    0.00    0.00     500&lt;br /&gt;outer_join_on_key                      1.00    0.00    0.00    0.00      10&lt;br /&gt;prepared_select                       24.00    9.12    1.49   10.61  100000&lt;br /&gt;select_1_row                          10.00    1.78    1.34    3.12  100000&lt;br /&gt;select_1_row_cache                     4.00    1.36    1.23    2.59  100000&lt;br /&gt;select_2_rows                         12.00    1.81    1.46    3.27  100000&lt;br /&gt;select_big                            14.00   10.88    2.34   13.22      80&lt;br /&gt;select_big_str                        13.00    4.72    0.76    5.48   10000&lt;br /&gt;select_cache                           1.00    0.76    0.10    0.86   10000&lt;br /&gt;select_cache2                         27.00    1.85    0.16    2.01   10000&lt;br /&gt;select_column+column                  12.00    1.76    1.17    2.93  100000&lt;br /&gt;select_diff_key                       35.00    0.15    0.01    0.16     500&lt;br /&gt;select_distinct                        1.00    0.80    0.14    0.94     800&lt;br /&gt;select_group                           2.00    0.52    0.09    0.61    2911&lt;br /&gt;select_group_when_MANY_tables         24.00    0.69    0.18    0.87   10000&lt;br /&gt;select_join                            0.00    0.24    0.04    0.28     100&lt;br /&gt;select_key                           146.00   27.12    3.51   30.63  200000&lt;br /&gt;select_key2                          164.00   28.05    3.45   31.50  200000&lt;br /&gt;select_key2_return_key               160.00   27.43    3.08   30.51  200000&lt;br /&gt;select_key2_return_prim              162.00   27.87    3.18   31.05  200000&lt;br /&gt;select_key_prefix                     80.00   23.80    3.15   26.95  200000&lt;br /&gt;select_key_prefix_join                 3.00    2.13    0.42    2.55     100&lt;br /&gt;select_key_return_key                154.00   27.36    3.04   30.40  200000&lt;br /&gt;select_many_fields                     4.00    1.68    1.52    3.20    2000&lt;br /&gt;select_range                           7.00    4.22    0.85    5.07     410&lt;br /&gt;select_range_key2                      2.00    1.76    0.30    2.06   25010&lt;br /&gt;select_range_prefix                    2.00    1.78    0.33    2.11   25010&lt;br /&gt;select_simple                          5.00    1.53    1.11    2.64  100000&lt;br /&gt;select_simple_cache                    5.00    1.38    1.12    2.50  100000&lt;br /&gt;select_simple_join                     0.00    0.28    0.06    0.34     500&lt;br /&gt;update_big                            11.00    0.00    0.00    0.00      10&lt;br /&gt;update_of_key                          6.00    0.72    0.43    1.15   50000&lt;br /&gt;update_of_key_big                      5.00    0.01    0.01    0.02     501&lt;br /&gt;update_of_primary_key_many_keys       18.00    0.01    0.01    0.02     256&lt;br /&gt;update_with_key                       24.00    4.00    2.59    6.59  300000&lt;br /&gt;update_with_key_prefix                 9.00    2.52    0.95    3.47  100000&lt;br /&gt;wisc_benchmark                         1.00    1.17    0.17    1.34     114&lt;br /&gt;TOTALS                              1583.00  329.57   65.53  395.10 3425950&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373489340812013?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373489340812013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373489340812013' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373489340812013'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373489340812013'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-benchmark-ran-2005-08-17.html' title='MySQL benchmark (ran 2005-08-17)'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373481902091431</id><published>2005-04-17T03:46:00.000-07:00</published><updated>2005-04-17T03:46:59.020-07:00</updated><title type='text'>Created_tmp_tables</title><content type='html'>The number of in-memory temporary tables created automatically by the server while executing statements. If Created_tmp_disk_tables is big, you may want to increase the tmp_table_size value to cause temporary tables to be memory-based instead of disk-based.&lt;br /&gt;&lt;br /&gt;set-variable    = tmp_table_size=128M&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373481902091431?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373481902091431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373481902091431' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373481902091431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373481902091431'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/createdtmptables.html' title='Created_tmp_tables'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373478414844017</id><published>2005-04-17T03:45:00.000-07:00</published><updated>2005-04-17T03:46:24.150-07:00</updated><title type='text'>Chang the Mysql client prompt</title><content type='html'>Changing the Mysql client prompt: (Mysql 4.0.2 and higher)&lt;br /&gt;&lt;br /&gt;(from http://dev.mysql.com/doc/mysql/en/mysql_Commands.html)&lt;br /&gt;&lt;br /&gt;e.g. "prompt \d\R\m&gt;" will show the current database + millitary hour + minutes&lt;br /&gt;&lt;br /&gt;Put in my.cnf&lt;br /&gt;&lt;br /&gt;[mysql]&lt;br /&gt;prompt="\\d\\R\\m&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373478414844017?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373478414844017/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373478414844017' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373478414844017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373478414844017'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/chang-mysql-client-prompt.html' title='Chang the Mysql client prompt'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373471038728482</id><published>2005-04-17T03:44:00.000-07:00</published><updated>2005-04-17T03:45:10.386-07:00</updated><title type='text'>Faster way of getting random rows in mysql instead of using order by rand()</title><content type='html'>1. create a new indexed column (= column_x) that's integer incremented for each table&lt;br /&gt;2. select count(*) to get # of rows&lt;br /&gt;3. use the app to generate X # of integers between 1 and last row&lt;br /&gt;4. select * from table where column_x in (rand1, rand2, rand3, ...)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373471038728482?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373471038728482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373471038728482' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373471038728482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373471038728482'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/faster-way-of-getting-random-rows-in.html' title='Faster way of getting random rows in mysql instead of using order by rand()'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373464969030576</id><published>2005-04-17T03:42:00.000-07:00</published><updated>2005-04-17T03:44:09.690-07:00</updated><title type='text'>End Query with \G instead of ;</title><content type='html'>You can use \G instead of ; for tables with lots of fields.&lt;br /&gt;&lt;br /&gt;mysql&gt; SHOW STATUS LIKE 'Qcache%';&lt;br /&gt;+-------------------------+-----------+&lt;br /&gt;| Variable_name           | Value     |&lt;br /&gt;+-------------------------+-----------+&lt;br /&gt;| Qcache_queries_in_cache | 6990      |&lt;br /&gt;| Qcache_inserts          | 6990      |&lt;br /&gt;| Qcache_hits             | 3987      |&lt;br /&gt;| Qcache_lowmem_prunes    | 0         |&lt;br /&gt;| Qcache_not_cached       | 621       |&lt;br /&gt;| Qcache_free_memory      | 176329432 |&lt;br /&gt;| Qcache_free_blocks      | 1         |&lt;br /&gt;| Qcache_total_blocks     | 13998     |&lt;br /&gt;+-------------------------+-----------+&lt;br /&gt;8 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; SHOW STATUS LIKE 'Qcache%' \G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;Variable_name: Qcache_queries_in_cache&lt;br /&gt;        Value: 7902&lt;br /&gt;*************************** 2. row ***************************&lt;br /&gt;Variable_name: Qcache_inserts&lt;br /&gt;        Value: 7902&lt;br /&gt;*************************** 3. row ***************************&lt;br /&gt;Variable_name: Qcache_hits&lt;br /&gt;        Value: 6456&lt;br /&gt;*************************** 4. row ***************************&lt;br /&gt;Variable_name: Qcache_lowmem_prunes&lt;br /&gt;        Value: 0&lt;br /&gt;*************************** 5. row ***************************&lt;br /&gt;Variable_name: Qcache_not_cached&lt;br /&gt;        Value: 3887&lt;br /&gt;*************************** 6. row ***************************&lt;br /&gt;Variable_name: Qcache_free_memory&lt;br /&gt;        Value: 172986416&lt;br /&gt;*************************** 7. row ***************************&lt;br /&gt;Variable_name: Qcache_free_blocks&lt;br /&gt;        Value: 1&lt;br /&gt;*************************** 8. row ***************************&lt;br /&gt;Variable_name: Qcache_total_blocks&lt;br /&gt;        Value: 15828&lt;br /&gt;8 rows in set (0.00 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373464969030576?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373464969030576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373464969030576' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373464969030576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373464969030576'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/end-query-with-g-instead-of.html' title='End Query with \G instead of ;'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373451253371769</id><published>2005-04-17T03:41:00.000-07:00</published><updated>2005-04-17T03:41:52.533-07:00</updated><title type='text'>Gauging MySQL performance- examples</title><content type='html'>mysql&gt; show variables like '%query_cache%';&lt;br /&gt;+-------------------+-----------+&lt;br /&gt;| Variable_name     | Value     |&lt;br /&gt;+-------------------+-----------+&lt;br /&gt;| have_query_cache  | YES       |&lt;br /&gt;| query_cache_limit | 4194304   |&lt;br /&gt;| query_cache_size  | 167772160 |&lt;br /&gt;| query_cache_type  | ON        |&lt;br /&gt;+-------------------+-----------+&lt;br /&gt;4 rows in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; show variables like '%query_cache%';&lt;br /&gt;+-------------------+-----------+&lt;br /&gt;| Variable_name     | Value     |&lt;br /&gt;+-------------------+-----------+&lt;br /&gt;| have_query_cache  | YES       |&lt;br /&gt;| query_cache_limit | 4194304   |&lt;br /&gt;| query_cache_size  | 167772160 |&lt;br /&gt;| query_cache_type  | ON        |&lt;br /&gt;+-------------------+-----------+&lt;br /&gt;4 rows in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; SHOW STATUS LIKE 'Qcache%';&lt;br /&gt;+-------------------------+-----------+&lt;br /&gt;| Variable_name           | Value     |&lt;br /&gt;+-------------------------+-----------+&lt;br /&gt;| Qcache_queries_in_cache | 2046      |&lt;br /&gt;| Qcache_inserts          | 2046      |&lt;br /&gt;| Qcache_hits             | 2385      |&lt;br /&gt;| Qcache_lowmem_prunes    | 0         |&lt;br /&gt;| Qcache_not_cached       | 1619      |&lt;br /&gt;| Qcache_free_memory      | 161661632 |&lt;br /&gt;| Qcache_free_blocks      | 1         |&lt;br /&gt;| Qcache_total_blocks     | 4111      |&lt;br /&gt;+-------------------------+-----------+&lt;br /&gt;8 rows in set (0.00 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373451253371769?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373451253371769/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373451253371769' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373451253371769'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373451253371769'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/gauging-mysql-performance-examples.html' title='Gauging MySQL performance- examples'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373446703121204</id><published>2005-04-17T03:40:00.000-07:00</published><updated>2005-04-17T03:41:07.030-07:00</updated><title type='text'>Example my.cnf for 4.0.X</title><content type='html'>[mysqld]&lt;br /&gt;datadir=/var/lib/mysql&lt;br /&gt;socket=/var/lib/mysql/mysql.sock&lt;br /&gt;set-variable    = key_buffer_size=160M&lt;br /&gt;set-variable    = join_buffer_size=64M&lt;br /&gt;set-variable    = max_allowed_packet=8M&lt;br /&gt;set-variable    = table_cache=256K&lt;br /&gt;set-variable    = sort_buffer_size=128M&lt;br /&gt;set-variable    = net_buffer_length=256K&lt;br /&gt;set-variable    = myisam_sort_buffer_size=128M&lt;br /&gt;set-variable    = read_buffer_size=8M&lt;br /&gt;set-variable    = long_query_time=5&lt;br /&gt;set-variable    = thread_cache_size=1M&lt;br /&gt;set-variable    = query_cache_size=8M&lt;br /&gt;set-variable    = read_rnd_buffer_size=32M&lt;br /&gt;set-variable    = tmp_table_size=64M&lt;br /&gt;set-variable    = record_buffer=4M&lt;br /&gt;set-variable    = log-slow-queries=/var/log/mysql_slow_queries.log&lt;br /&gt;set-variable    = long_query_time=3&lt;br /&gt;set-variable    = query_cache_type=1&lt;br /&gt;set-variable    = query_cache_size=256M&lt;br /&gt;set-variable    = query_cache_limit=4M&lt;br /&gt;skip-innodb&lt;br /&gt;&lt;br /&gt;[mysql.server]&lt;br /&gt;user=mysql&lt;br /&gt;basedir=/var/lib&lt;br /&gt;&lt;br /&gt;[safe_mysqld]&lt;br /&gt;err-log=/var/log/mysqld.log&lt;br /&gt;pid-file=/var/run/mysqld/mysqld.pid&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373446703121204?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373446703121204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373446703121204' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373446703121204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373446703121204'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/example-mycnf-for-40x.html' title='Example my.cnf for 4.0.X'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373433782875048</id><published>2005-04-17T03:38:00.000-07:00</published><updated>2005-04-17T03:39:56.036-07:00</updated><title type='text'>MySQL date calculations</title><content type='html'>e.g. 2 days ago till today:&lt;br /&gt;&lt;br /&gt;select domain, count(*) as cnt from referrers where date &gt;= current_date()-2 group by domain order by cnt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Simple Date Calculations&lt;br /&gt;Date calculations are relatively easy. The first function we're going to look at is the YEAR() function, which returns a year from a given date. For example:&lt;br /&gt;&lt;br /&gt;mysql&gt; SELECT YEAR('2003-03-31');&lt;br /&gt;+--------------------+&lt;br /&gt;| YEAR('2003-03-31') |&lt;br /&gt;+--------------------+&lt;br /&gt;|               2003 |&lt;br /&gt;+--------------------+&lt;br /&gt;&lt;br /&gt;We can perform simple arithmetic on a date using the '+' and '-' operators. For example, to find out which year is five years ahead of a given date, you can use:&lt;br /&gt;mysql&gt; SELECT YEAR('2003-03-31')+5;&lt;br /&gt;+----------------------+&lt;br /&gt;| YEAR('2003-03-31')+5 |&lt;br /&gt;+----------------------+&lt;br /&gt;|                 2008 |&lt;br /&gt;+----------------------+&lt;br /&gt;&lt;br /&gt;And to find out which year was five years in the past:&lt;br /&gt;mysql&gt; SELECT YEAR('2003-03-31')-5;&lt;br /&gt;+----------------------+&lt;br /&gt;| YEAR('2003-03-31')-5 |&lt;br /&gt;+----------------------+&lt;br /&gt;|                 1998 |&lt;br /&gt;+----------------------+&lt;br /&gt;&lt;br /&gt;Of course you don't have to hard-code the date. MySQL is quite capable of telling the date and time, using the NOW() function:&lt;br /&gt;mysql&gt; SELECT NOW();&lt;br /&gt;+---------------------+&lt;br /&gt;| NOW()               |&lt;br /&gt;+---------------------+&lt;br /&gt;| 2003-03-31 00:32:21 |&lt;br /&gt;+---------------------+&lt;br /&gt;&lt;br /&gt;or just the date with the CURRENT_DATE() function:&lt;br /&gt;mysql&gt; SELECT CURRENT_DATE();&lt;br /&gt;+----------------+&lt;br /&gt;| CURRENT_DATE() |&lt;br /&gt;+----------------+&lt;br /&gt;| 2003-03-31     |&lt;br /&gt;+----------------+&lt;br /&gt;&lt;br /&gt;There are also functions for the other date and time intervals; MONTH(), DAYOFMONTH(), HOUR(), MINUTE() and SECOND(). For example:&lt;br /&gt;mysql&gt; SELECT MONTH(NOW()) AS m,&lt;br /&gt;DAYOFMONTH(NOW()) AS d,&lt;br /&gt;HOUR(NOW()) AS h,&lt;br /&gt;MINUTE(NOW()) AS m,&lt;br /&gt;SECOND(NOW()) AS s;&lt;br /&gt;+------+------+------+------+------+&lt;br /&gt;| m    | d    | h    | m    | s    |&lt;br /&gt;+------+------+------+------+------+&lt;br /&gt;|    3 |   31 |    1 |   53 |   38 |&lt;br /&gt;+------+------+------+------+------+&lt;br /&gt;&lt;br /&gt;The DAYOFMONTH() function is an exception to the naming conventions because there are a number of other ways to return the day. DAYOFMONTH() returns the day as a numeric from 1 to 31, but there is also DAYNAME() which returns the actual name of the day, DAYOFWEEK() which returns a number from 1 (Sunday) to 7(Saturday) and DAYOFYEAR() returning a number from 1 to 366. Some examples:&lt;br /&gt;&lt;br /&gt;mysql&gt; SELECT DAYNAME('2000-01-01');&lt;br /&gt;+-----------------------+&lt;br /&gt;| DAYNAME('2000-01-01') |&lt;br /&gt;+-----------------------+&lt;br /&gt;| Saturday              |&lt;br /&gt;+-----------------------+&lt;br /&gt;&lt;br /&gt;mysql&gt; SELECT DAYOFWEEK('2000-01-01');&lt;br /&gt;+-------------------------+&lt;br /&gt;| DAYOFWEEK('2000-01-01') |&lt;br /&gt;+-------------------------+&lt;br /&gt;|                       7 |&lt;br /&gt;+-------------------------+&lt;br /&gt;&lt;br /&gt;mysql&gt; SELECT DAYOFYEAR('2000-12-31');&lt;br /&gt;+-------------------------+&lt;br /&gt;| DAYOFYEAR('2000-12-31') |&lt;br /&gt;+-------------------------+&lt;br /&gt;|                     366 |&lt;br /&gt;+-------------------------+&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One of the most commonly performed date calculations is one which calculates age. Unfortunately there isn't a function to do it, so you need to do a bit of thinking. Let's begin with doing some simple arithmetic - you can see when I'm running these queries from the earlier results (31 March 2003). First, we'll simply subtract the year of birth from the current year. If you're reading this article well after I wrote it, of course your results may be different:&lt;br /&gt;mysql&gt; SELECT YEAR(CURRENT_DATE)-YEAR('1971-01-01');&lt;br /&gt;+---------------------------------------+&lt;br /&gt;| YEAR(CURRENT_DATE)-YEAR('1971-01-01') |&lt;br /&gt;+---------------------------------------+&lt;br /&gt;|                                    32 |&lt;br /&gt;+---------------------------------------+&lt;br /&gt;&lt;br /&gt;If you were using this to return the age, the result would be correct. Someone born on the 1st of January 1971 would be 32 years old on the 31st of March 2003. But let's test for someone born on the 31st of December:&lt;br /&gt;mysql&gt; SELECT YEAR(CURRENT_DATE)-YEAR('1971-12-31');&lt;br /&gt;+---------------------------------------+&lt;br /&gt;| YEAR(CURRENT_DATE)-YEAR('1971-12-31') |&lt;br /&gt;+---------------------------------------+&lt;br /&gt;|                                    32 |&lt;br /&gt;+---------------------------------------+&lt;br /&gt;&lt;br /&gt;Here the age is wrong. This person would not have turned 32 yet. The problem is that the calculation above only checks the year part of the date. It comes down to subtracting 1971 from 2003, regardless of the month and day. The best way to do this is to compare whether the current month and day are larger than the birth month and day. If it is, a full year has passed, and the year portion of the calculation can be left. If it isn't, a full year hasn't passed, and you need to subtract one from the year portion. It sounds tricky, but it isn't really. Let's break it down slowly. It helps us greatly that MySQL evaluates a true expression to 1, and a false expression to 0. For example:&lt;br /&gt;mysql&gt; SELECT 23&gt;19;&lt;br /&gt;+-------+&lt;br /&gt;| 23&gt;19 |&lt;br /&gt;+-------+&lt;br /&gt;|     1 |&lt;br /&gt;+-------+&lt;br /&gt;&lt;br /&gt;mysql&gt; SELECT 23&lt;19;&gt; SELECT RIGHT('abcdef',2);&lt;br /&gt;+-------------------+&lt;br /&gt;| RIGHT('abcdef',2) |&lt;br /&gt;+-------------------+&lt;br /&gt;| ef                |&lt;br /&gt;+-------------------+&lt;br /&gt;&lt;br /&gt;This returns 2 characters, starting from the right of the string, thus 'ef'. If you ask for more characters than the string is long, MySQL simply returns the whole string:&lt;br /&gt;mysql&gt; SELECT RIGHT('abcdef',9);&lt;br /&gt;+-------------------+&lt;br /&gt;| RIGHT('abcdef',9) |&lt;br /&gt;+-------------------+&lt;br /&gt;| abcdef            |&lt;br /&gt;+-------------------+&lt;br /&gt;&lt;br /&gt;So, to return the 'MM-DD' portion of a date, you need to return the five rightmost characters, for example:&lt;br /&gt;mysql&gt; SELECT RIGHT(CURRENT_DATE(),5);&lt;br /&gt;+-------------------------+&lt;br /&gt;| RIGHT(CURRENT_DATE(),5) |&lt;br /&gt;+-------------------------+&lt;br /&gt;| 03-31                   |&lt;br /&gt;+-------------------------+&lt;br /&gt;&lt;br /&gt;Now we have everything we need to calculate an age. The query will have a portion that calculates the difference in years, and then we'll subtract either 0 or 1, depending on the month-day portion. Here is the full query:&lt;br /&gt;mysql&gt; SELECT YEAR(CURRENT_DATE()) - YEAR('1971-12-31')&lt;br /&gt;- (RIGHT(CURRENT_DATE(),5)&lt;'12-31') AS age;&lt;br /&gt;+------+&lt;br /&gt;| age  |&lt;br /&gt;+------+&lt;br /&gt;|   31 |&lt;br /&gt;+------+&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373433782875048?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373433782875048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373433782875048' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373433782875048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373433782875048'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-date-calculations.html' title='MySQL date calculations'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373427994166708</id><published>2005-04-17T03:37:00.000-07:00</published><updated>2005-04-17T03:37:59.943-07:00</updated><title type='text'>MySQL Explain example</title><content type='html'>EXPLAIN SELECT employee_number,firstname,surname FROM employee WHERE employee_number= '10875';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;+----------+------+---------------+------+---------+------+------+------------+&lt;br /&gt;| table    | type | possible_keys | key  | key_len | ref  | rows | Extra      |&lt;br /&gt;+----------+------+---------------+------+---------+------+------+------------+&lt;br /&gt;| employee | ALL  | NULL          | NULL |    NULL | NULL |    2 | where used |&lt;br /&gt;+----------+------+---------------+------+---------+------+------+------------+&lt;br /&gt;&lt;br /&gt;So what are all these things?&lt;br /&gt;&lt;br /&gt;-table shows us which table the output is about (for when you join many tables in the query)&lt;br /&gt;-type is an important one - it tells us which type of join is being used. From best to worst the types are: system, const, eq_ref, ref, range, index, all&lt;br /&gt;-possible_keys Shows which possible indexes apply to this table&lt;br /&gt;-key And which one is actually used&lt;br /&gt;-key_len give us the length of the key used. The shorter that better.&lt;br /&gt;-ref Tells us which column, or a constant, is used&lt;br /&gt;-rows Number of rows mysql believes it must examine to get the data&lt;br /&gt;extra Extra info - the bad ones to see here are "using temporary" and "using filesort"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373427994166708?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373427994166708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373427994166708' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373427994166708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373427994166708'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-explain-example.html' title='MySQL Explain example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373412859241012</id><published>2005-04-17T03:34:00.000-07:00</published><updated>2005-04-17T03:35:28.593-07:00</updated><title type='text'>Some built-in MySQL functions</title><content type='html'>mysql&gt; select version();&lt;br /&gt;+---------------+&lt;br /&gt;| version()     |&lt;br /&gt;+---------------+&lt;br /&gt;| 3.23.29-gamma |&lt;br /&gt;+---------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select database();&lt;br /&gt;+------------+&lt;br /&gt;| database() |&lt;br /&gt;+------------+&lt;br /&gt;| main       |&lt;br /&gt;+------------+&lt;br /&gt;1 row in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; SELECT PASSWORD("mypass");&lt;br /&gt;+--------------------+&lt;br /&gt;| PASSWORD("mypass") |&lt;br /&gt;+--------------------+&lt;br /&gt;| 6f8c114b58f2ce9e   |&lt;br /&gt;+--------------------+&lt;br /&gt;1 row in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select md5('test');&lt;br /&gt;+----------------------------------+&lt;br /&gt;| md5('test')                      |&lt;br /&gt;+----------------------------------+&lt;br /&gt;| 098f6bcd4621d373cade4e832627b4f6 |&lt;br /&gt;+----------------------------------+&lt;br /&gt;1 row in set (0.02 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373412859241012?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373412859241012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373412859241012' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373412859241012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373412859241012'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/some-built-in-mysql-functions.html' title='Some built-in MySQL functions'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373401545252190</id><published>2005-04-17T03:33:00.000-07:00</published><updated>2005-04-17T03:33:35.453-07:00</updated><title type='text'>Problem in Mysql with equality comparison with float</title><content type='html'>There is a general problem when testing a floating point field for equality. The test (field=14.40) doesn't work because field is not exactly 14.40, but it could be 13.9999 or 14.0001. Use this test instead: (field between 13.9999 and 14.0001). Moreover, as a general rule, if you want precise results, don't use float, but decimal, and test by ranges (between y and z), instead of exact values (= x).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373401545252190?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373401545252190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373401545252190' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373401545252190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373401545252190'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/problem-in-mysql-with-equality.html' title='Problem in Mysql with equality comparison with float'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373397287844591</id><published>2005-04-17T03:31:00.000-07:00</published><updated>2005-04-17T03:32:52.880-07:00</updated><title type='text'>Do a join on the same table in MySQL</title><content type='html'>You can join the same table in mysql!&lt;br /&gt;&lt;br /&gt;mysql&gt; select mv2.name, mv1.quantity&lt;br /&gt;    -&gt; from dw.MAILVRS mv1, dw.MAILVRS mv2&lt;br /&gt;    -&gt; where mv1.version_recnum = 124475 and mv1.package_recnum = mv2.dataflex_recnum_one;&lt;br /&gt;&lt;br /&gt;+---------+----------+&lt;br /&gt;| name    | quantity |&lt;br /&gt;+---------+----------+&lt;br /&gt;| Kit A   |    25000 |&lt;br /&gt;| Control |    50000 |&lt;br /&gt;| Kit E   |    25000 |&lt;br /&gt;+---------+----------+&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373397287844591?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373397287844591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373397287844591' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373397287844591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373397287844591'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/do-join-on-same-table-in-mysql.html' title='Do a join on the same table in MySQL'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373390202953350</id><published>2005-04-17T03:29:00.000-07:00</published><updated>2005-04-17T03:31:42.030-07:00</updated><title type='text'>MySQL outer join SQL tutorial/examples</title><content type='html'>First of all, outer joins are for instances where info is being looked up on another table and you want rows returned even though nothing was matched for a particular id, e.g.:&lt;br /&gt;&lt;br /&gt;create table food (&lt;br /&gt; id int unsigned primary key auto_increment,&lt;br /&gt; food char(16),&lt;br /&gt; yummy char(1),&lt;br /&gt; animal char(16)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;create table animals (&lt;br /&gt; name char(16) primary key,&lt;br /&gt; weight int unsigned&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;insert into food values&lt;br /&gt;(NULL, 'apple', 'Y', 'human'),&lt;br /&gt;(NULL, 'oranges', 'Y', 'human'),&lt;br /&gt;(NULL, 'apple', 'N', 'dog'),&lt;br /&gt;(NULL, 'oranges', 'N', 'dog'),&lt;br /&gt;(NULL, 'apple', 'N', 'cat'),&lt;br /&gt;(NULL, 'oranges', 'N', 'cat');&lt;br /&gt;&lt;br /&gt;insert into animals values&lt;br /&gt;('cat', 12),&lt;br /&gt;('dog', 25);&lt;br /&gt;&lt;br /&gt;table 'food'&lt;br /&gt;&lt;br /&gt;id    food        yummy        animal&lt;br /&gt;---    ----        -----        ------&lt;br /&gt;1    apple        Y        human&lt;br /&gt;2    oranges        Y        human&lt;br /&gt;3    apple        N        dog&lt;br /&gt;4    oranges        N        dog&lt;br /&gt;5    apple        N        cat&lt;br /&gt;6    oranges        N        cat&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;table 'animals'&lt;br /&gt;&lt;br /&gt;name    weight&lt;br /&gt;----    ------&lt;br /&gt;Cat    12&lt;br /&gt;Dog    25&lt;br /&gt;&lt;br /&gt;Let's say you want a list of all the foods and the weight of the animals.&lt;br /&gt;&lt;br /&gt;If you do:&lt;br /&gt;&lt;br /&gt;select f.*, a.weight&lt;br /&gt;from food f, animals a&lt;br /&gt;where f.animal = a.name&lt;br /&gt;&lt;br /&gt;In this case the result would be:&lt;br /&gt;&lt;br /&gt;+----+---------+-------+--------+--------+&lt;br /&gt;| id | food    | yummy | animal | weight |&lt;br /&gt;+----+---------+-------+--------+--------+&lt;br /&gt;|  5 | apple   | N     | cat    |     12 |&lt;br /&gt;|  6 | oranges | N     | cat    |     12 |&lt;br /&gt;|  3 | apple   | N     | dog    |     25 |&lt;br /&gt;|  4 | oranges | N     | dog    |     25 |&lt;br /&gt;+----+---------+-------+--------+--------+&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Notice that humans is missing, but if you want the humans to show up even&lt;br /&gt;though there's no human entry in the 'animals' table you have to do an&lt;br /&gt;outer join (aka LEFT [OUTER] JOIN in Mysql):&lt;br /&gt;&lt;br /&gt;select f.*, a.weight&lt;br /&gt;from food f&lt;br /&gt;LEFT JOIN animals a on (f.animal=a.name)&lt;br /&gt;&lt;br /&gt;In this case the result would be:&lt;br /&gt;&lt;br /&gt;+----+---------+-------+--------+--------+&lt;br /&gt;| id | food    | yummy | animal | weight |&lt;br /&gt;+----+---------+-------+--------+--------+&lt;br /&gt;|  1 | apple   | Y     | human  |   NULL |&lt;br /&gt;|  2 | oranges | Y     | human  |   NULL |&lt;br /&gt;|  3 | apple   | N     | dog    |     25 |&lt;br /&gt;|  4 | oranges | N     | dog    |     25 |&lt;br /&gt;|  5 | apple   | N     | cat    |     12 |&lt;br /&gt;|  6 | oranges | N     | cat    |     12 |&lt;br /&gt;+----+---------+-------+--------+--------+&lt;br /&gt;&lt;br /&gt;Here are some more examples:&lt;br /&gt;&lt;br /&gt;SELECT T.name, V.value, T.unit, T.id, A.Product_id&lt;br /&gt;FROM attribute_type AS T&lt;br /&gt;LEFT JOIN attribute AS A ON ( T.id = A.type_id AND A.Product_id = 21 )&lt;br /&gt;LEFT JOIN attribute_value AS V ON ( A.value_id = V.id );&lt;br /&gt;&lt;br /&gt;select j.id, j.job_id, d.NAMES, e.DETAILS1, j.file_name, j.job_owner, j.import_date&lt;br /&gt;from db.summary_jobs j&lt;br /&gt;left join db.EST e on (j.job_id=e.JOB_NUMBER)&lt;br /&gt;left join db.DEB d on (e.DEBTOR=d.AC_NO)&lt;br /&gt;order by j.job_id desc limit&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373390202953350?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373390202953350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373390202953350' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373390202953350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373390202953350'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-outer-join-sql-tutorialexamples.html' title='MySQL outer join SQL tutorial/examples'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373374850564478</id><published>2005-04-17T03:28:00.000-07:00</published><updated>2005-04-17T03:29:08.506-07:00</updated><title type='text'>How  to alter mysql table column to AUTO_INCREMENT</title><content type='html'>mysql&gt; set insert_id=7;&lt;br /&gt;  Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;  mysql&gt; alter table fixtures modify column id int auto_increment;&lt;br /&gt;  Query OK, 7 rows affected (0.01 sec)&lt;br /&gt;  Records: 7  Duplicates: 0  Warnings&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373374850564478?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373374850564478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373374850564478' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373374850564478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373374850564478'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/how-to-alter-mysql-table-column-to.html' title='How  to alter mysql table column to AUTO_INCREMENT'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373368445936738</id><published>2005-04-17T03:27:00.000-07:00</published><updated>2005-04-17T03:28:04.460-07:00</updated><title type='text'>MySQL INSERT SELECT example</title><content type='html'>insert into user (id, name, email, passwd, ref, joindate) select idm, user_name, email, pass, refferal, sysdate() from db.members;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373368445936738?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373368445936738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373368445936738' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373368445936738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373368445936738'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-insert-select-example.html' title='MySQL INSERT SELECT example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373355497222978</id><published>2005-04-17T03:25:00.000-07:00</published><updated>2005-04-17T03:25:54.973-07:00</updated><title type='text'>Export from mysql into fixed length file</title><content type='html'>SELECT * INTO OUTFILE file_name&lt;br /&gt;FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY ''&lt;br /&gt;LINES TERMINATED BY "\n"&lt;br /&gt;FROM my_table;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373355497222978?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373355497222978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373355497222978' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373355497222978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373355497222978'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/export-from-mysql-into-fixed-length.html' title='Export from mysql into fixed length file'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373348029077044</id><published>2005-04-17T03:24:00.000-07:00</published><updated>2005-04-17T04:07:18.510-07:00</updated><title type='text'>Mysql Search and Replace example</title><content type='html'>Doing search and replace in mysql, e.g.:&lt;br /&gt;&lt;br /&gt;update tablename set field = replace(field,'search_for_this','replace_with_this');&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373348029077044?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373348029077044/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373348029077044' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373348029077044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373348029077044'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-search-and-replace-example.html' title='Mysql Search and Replace example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373342001964094</id><published>2005-04-17T03:22:00.000-07:00</published><updated>2005-04-17T03:23:40.020-07:00</updated><title type='text'>Show Processlist</title><content type='html'>In mysql do a "show processlist" to see what queries are running.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373342001964094?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373342001964094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373342001964094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373342001964094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373342001964094'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/show-processlist.html' title='Show Processlist'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373336489653679</id><published>2005-04-17T03:21:00.000-07:00</published><updated>2005-04-17T03:22:44.896-07:00</updated><title type='text'>MySQL slow queries log</title><content type='html'>start safe_mysqld like this to catch slow queries:&lt;br /&gt;&lt;br /&gt;./bin/safe_mysqld --log-slow-queries &amp;&lt;br /&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;To use it, you need to add --log-slow-queries to your mysqld startup.&lt;br /&gt;&lt;br /&gt;I added it to my /etc/rc.d/init.d/mysql file like so:&lt;br /&gt;&lt;br /&gt;$bindir/safe_mysqld --user=$mysql_daemon_user --datadir=$datadir --pid-file=$pid_file --log=$log_file  --log-slow-queries &amp;amp;&lt;br /&gt;&lt;br /&gt;It does appear to put stuff into a different place, namely:&lt;br /&gt;&lt;br /&gt;/var/lib/mysql/hostname-slow.log&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373336489653679?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373336489653679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373336489653679' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373336489653679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373336489653679'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-slow-queries-log.html' title='MySQL slow queries log'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373328384853993</id><published>2005-04-17T03:20:00.000-07:00</published><updated>2005-04-17T03:21:23.850-07:00</updated><title type='text'>MySQL replication instructions</title><content type='html'>As of version 3.23.15 (try to use 3.23.29 or later), MySQL supports one-way replication. Since most web applications usually have more reads than writes, an architecture which distributes reads across multiple servers can be very beneficial.&lt;br /&gt;&lt;br /&gt;In typical MySQL fashion, setting up replication is trivial. On your master server add this to your my.cnf file:&lt;br /&gt;&lt;br /&gt;[mysqld]&lt;br /&gt;log-bin&lt;br /&gt;server-id=1 &lt;br /&gt;&lt;br /&gt;And add a replication user id for slaves to log in as:&lt;br /&gt;&lt;br /&gt;GRANT FILE ON *.* TO repl@"%" IDENTIFIED BY 'foobar'; &lt;br /&gt;&lt;br /&gt;Then on your slave servers:&lt;br /&gt;&lt;br /&gt;[mysqld]&lt;br /&gt;set-variable = max_connections=200&lt;br /&gt;log-bin&lt;br /&gt;master-host=192.168.0.1&lt;br /&gt;master-user=repl&lt;br /&gt;master-password=foobar&lt;br /&gt;master-port=3306&lt;br /&gt;server-id=2 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Make sure each slave has its own unique server-id. And since these will be read-only slaves, you can start them with these options to speed them up a bit:&lt;br /&gt;&lt;br /&gt;--skip-bdb --low-priority-updates --delay-key-write-for-all-tables &lt;br /&gt;&lt;br /&gt;Stop your master server. Copy the table files to each of your slave servers. Restart the master, then start all the slaves. And you are done. Combining MySQL replication with a Squid reverse cache and redirector and you might have an architecture like this:&lt;br /&gt;&lt;br /&gt;You would then write your application to send all database writes to the master server and all reads to the local slave. It is also possible to set up two-way replication, but you would need to supply your own application-level logic to maintain atomicity of distributed writes. And you lose a lot of the advantages of this architecture if you do this as the writes would have to go to all the slaves anyway.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373328384853993?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373328384853993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373328384853993' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373328384853993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373328384853993'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-replication-instructions.html' title='MySQL replication instructions'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373318447621689</id><published>2005-04-17T03:19:00.000-07:00</published><updated>2005-04-17T03:20:11.936-07:00</updated><title type='text'>MySQL SELECT CASE  example</title><content type='html'>select&lt;br /&gt;CASE month when "01" then "January"&lt;br /&gt;when "02" then "February"&lt;br /&gt;when "03" then "March"&lt;br /&gt;when "04" then "April"&lt;br /&gt;when "05" then "May"&lt;br /&gt;when "06" then "June"&lt;br /&gt;when "07" then "July"&lt;br /&gt;when "08" then "August"&lt;br /&gt;when "09" then "September"&lt;br /&gt;when "10" then "October"&lt;br /&gt;when "11" then "November"&lt;br /&gt;when "12" then "December"&lt;br /&gt;END&lt;br /&gt;from calendar where year = "2005" order by month&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373318447621689?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373318447621689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373318447621689' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373318447621689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373318447621689'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/mysql-select-case-example.html' title='MySQL SELECT CASE  example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373312495565740</id><published>2005-04-17T03:17:00.000-07:00</published><updated>2005-04-17T03:18:44.956-07:00</updated><title type='text'>Transactions example</title><content type='html'>Transactions are used to make ensure that a series of statements either all get processed or don't get processed at all -- basically all or nothing. Why is this important? Let's consider a simple banking example. You transfer $500 from one bank account into another:&lt;br /&gt;&lt;br /&gt;1. - $500 from account A&lt;br /&gt;2. + $500 to account B&lt;br /&gt;&lt;br /&gt;Step 1 processes successfully, but something bad happens between step 1 and 2. Where is your money now -- you just lost $500!! This is clearly not acceptable, we need to be able to confidently say that steps 1 and 2 must all process successfully, or none of it can process at all.&lt;br /&gt;&lt;br /&gt;Enter the concept of transactions. With transactions, we would be able to do this:&lt;br /&gt;&lt;br /&gt;1. BEGIN TRANSACTION&lt;br /&gt;2. - $500 from account A&lt;br /&gt;3. + $500 to account B&lt;br /&gt;4. END TRANSACTION&lt;br /&gt;&lt;br /&gt;Now steps 1 to 4 are treated as one atomic operation. If anything fails between steps 1 to 4, the entire operation is aborted and we revert back to the way things were before we started. The worst that can happen here is that the money doesn't get transferred, but at least you will not lose $500.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373312495565740?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373312495565740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373312495565740' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373312495565740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373312495565740'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/transactions-example.html' title='Transactions example'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373300675955695</id><published>2005-04-17T03:15:00.000-07:00</published><updated>2005-04-17T03:16:46.763-07:00</updated><title type='text'>Setup New Users in MySQL</title><content type='html'>The examples below show how to use the mysql client to set up new users. These examples assume that privileges are set up according to the defaults described in the previous section. This means that to make changes, you must be on the same machine where mysqld is running, you must connect as the MySQL root user, and the root user must have the insert privilege for the mysql database and the reload administrative privilege. Also, if you have changed the root user password, you must specify it for the mysql commands below.&lt;br /&gt;&lt;br /&gt;You can add new users by issuing GRANT statements:&lt;br /&gt;&lt;br /&gt;shell&gt; mysql --user=root mysql&lt;br /&gt;mysql&gt; GRANT ALL PRIVILEGES ON *.* TO monty@localhost&lt;br /&gt;           IDENTIFIED BY 'some_pass' WITH GRANT OPTION;&lt;br /&gt;mysql&gt; GRANT ALL PRIVILEGES ON *.* TO monty@"%"&lt;br /&gt;           IDENTIFIED BY 'some_pass' WITH GRANT OPTION;&lt;br /&gt;mysql&gt; GRANT RELOAD,PROCESS ON *.* TO admin@localhost;&lt;br /&gt;mysql&gt; GRANT USAGE ON *.* TO dummy@localhost;&lt;br /&gt;&lt;br /&gt;These GRANT statements set up three new users:&lt;br /&gt;&lt;br /&gt;monty&lt;br /&gt;A full superuser who can connect to the server from anywhere, but who must use a password 'some_pass' to do so. Note that we must issue GRANT statements for both monty@localhost and monty@"%". If we don't add the entry with localhost, the anonymous user entry for localhost that is created by mysql_install_db will take precedence when we connect from the local host, because it has a more specific Host field value and thus comes earlier in the user table sort order.&lt;br /&gt;admin&lt;br /&gt;A user who can connect from localhost without a password and who is granted the reload and process administrative privileges. This allows the user to execute the mysqladmin reload, mysqladmin refresh, and mysqladmin flush-* commands, as well as mysqladmin processlist . No database-related privileges are granted. (They can be granted later by issuing additional GRANT statements.)&lt;br /&gt;dummy&lt;br /&gt;A user who can connect without a password, but only from the local host. The global privileges are all set to 'N' -- the USAGE privilege type allows you to create a user with no privileges. It is assumed that you will grant database-specific privileges later.&lt;br /&gt;You can also add the same user access information directly by issuing INSERT statements and then telling the server to reload the grant tables:&lt;br /&gt;&lt;br /&gt;shell&gt; mysql --user=root mysql&lt;br /&gt;mysql&gt; INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),&lt;br /&gt;                'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');&lt;br /&gt;mysql&gt; INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),&lt;br /&gt;                'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');&lt;br /&gt;mysql&gt; INSERT INTO user SET Host='localhost',User='admin',&lt;br /&gt;                 Reload_priv='Y', Process_priv='Y';&lt;br /&gt;mysql&gt; INSERT INTO user (Host,User,Password)&lt;br /&gt;                        VALUES('localhost','dummy','');&lt;br /&gt;mysql&gt; FLUSH PRIVILEGES;&lt;br /&gt;&lt;br /&gt;Depending on your MySQL version, you may have to use a different number of 'Y' values above (versions prior to Version 3.22.11 had fewer privilege columns). For the admin user, the more readable extended INSERT syntax that is available starting with Version 3.22.11 is used.&lt;br /&gt;&lt;br /&gt;Note that to set up a superuser, you need only create a user table entry with the privilege fields set to 'Y'. No db or host table entries are necessary.&lt;br /&gt;&lt;br /&gt;The privilege columns in the user table were not set explicitly in the last INSERT statement (for the dummy user), so those columns are assigned the default value of 'N'. This is the same thing that GRANT USAGE does.&lt;br /&gt;&lt;br /&gt;The following example adds a user custom who can connect from hosts localhost, server.domain, and whitehouse.gov. He wants to access the bankaccount database only from localhost, the expenses database only from whitehouse.gov, and the customer database from all three hosts. He wants to use the password stupid from all three hosts.&lt;br /&gt;&lt;br /&gt;To set up this user's privileges using GRANT statements, run these commands:&lt;br /&gt;&lt;br /&gt;shell&gt; mysql --user=root mysql&lt;br /&gt;mysql&gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP&lt;br /&gt;           ON bankaccount.*&lt;br /&gt;           TO custom@localhost&lt;br /&gt;           IDENTIFIED BY 'stupid';&lt;br /&gt;mysql&gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP&lt;br /&gt;           ON expenses.*&lt;br /&gt;           TO custom@whitehouse.gov&lt;br /&gt;           IDENTIFIED BY 'stupid';&lt;br /&gt;mysql&gt; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP&lt;br /&gt;           ON customer.*&lt;br /&gt;           TO custom@'%'&lt;br /&gt;           IDENTIFIED BY 'stupid';&lt;br /&gt;&lt;br /&gt;The reason that we do to grant statements for the user 'custom' is that we want the give the user access to MySQL both from the local machine with Unix sockets and from the remote machine 'whitehouse.gov' over TCP/IP.&lt;br /&gt;&lt;br /&gt;To set up the user's privileges by modifying the grant tables directly, run these commands (note the FLUSH PRIVILEGES at the end):&lt;br /&gt;&lt;br /&gt;shell&gt; mysql --user=root mysql&lt;br /&gt;mysql&gt; INSERT INTO user (Host,User,Password)&lt;br /&gt;       VALUES('localhost','custom',PASSWORD('stupid'));&lt;br /&gt;mysql&gt; INSERT INTO user (Host,User,Password)&lt;br /&gt;       VALUES('server.domain','custom',PASSWORD('stupid'));&lt;br /&gt;mysql&gt; INSERT INTO user (Host,User,Password)&lt;br /&gt;       VALUES('whitehouse.gov','custom',PASSWORD('stupid'));&lt;br /&gt;mysql&gt; INSERT INTO db&lt;br /&gt;       (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,&lt;br /&gt;        Create_priv,Drop_priv)&lt;br /&gt;       VALUES&lt;br /&gt;       ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');&lt;br /&gt;mysql&gt; INSERT INTO db&lt;br /&gt;       (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,&lt;br /&gt;        Create_priv,Drop_priv)&lt;br /&gt;       VALUES&lt;br /&gt;       ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');&lt;br /&gt;mysql&gt; INSERT INTO db&lt;br /&gt;       (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,&lt;br /&gt;        Create_priv,Drop_priv)&lt;br /&gt;       VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y');&lt;br /&gt;mysql&gt; FLUSH PRIVILEGES;&lt;br /&gt;&lt;br /&gt;The first three INSERT statements add user table entries that allow user custom to connect from the various hosts with the given password, but grant no permissions to him (all privileges are set to the default value of 'N'). The next three INSERT statements add db table entries that grant privileges to custom for the bankaccount, expenses, and customer databases, but only when accessed from the proper hosts. As usual, when the grant tables are modified directly, the server must be told to reload them (with FLUSH PRIVILEGES) so that the privilege changes take effect.&lt;br /&gt;&lt;br /&gt;If you want to give a specific user access from any machine in a given domain, you can issue a GRANT statement like the following:&lt;br /&gt;&lt;br /&gt;mysql&gt; GRANT ...&lt;br /&gt;           ON *.*&lt;br /&gt;           TO myusername@"%.mydomainname.com"&lt;br /&gt;           IDENTIFIED BY 'mypassword';&lt;br /&gt;&lt;br /&gt;To do the same thing by modifying the grant tables directly, do this:&lt;br /&gt;&lt;br /&gt;mysql&gt; INSERT INTO user VALUES ('%.mydomainname.com', 'myusername',&lt;br /&gt;           PASSWORD('mypassword'),...);&lt;br /&gt;mysql&gt; FLUSH PRIVILEGES;&lt;br /&gt;&lt;br /&gt;You can also use xmysqladmin, mysql_webadmin, and even xmysql to insert, change, and update values in the grant tables. You can find these utilities in the Contrib directory of the MySQL Website.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373300675955695?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373300675955695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373300675955695' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373300675955695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373300675955695'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/setup-new-users-in-mysql.html' title='Setup New Users in MySQL'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373291410982803</id><published>2005-04-17T03:12:00.000-07:00</published><updated>2005-04-17T03:15:14.110-07:00</updated><title type='text'>LOAD DATA INFILE example - importing data from csv into mysql</title><content type='html'>LOAD DATA INFILE "/home/mysql/data/my_table.csv" INTO TABLE my_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373291410982803?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373291410982803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373291410982803' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373291410982803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373291410982803'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/load-data-infile-example-importing.html' title='LOAD DATA INFILE example - importing data from csv into mysql'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12233913.post-111373275045025083</id><published>2005-04-17T03:11:00.000-07:00</published><updated>2005-04-17T03:12:30.450-07:00</updated><title type='text'>Installing MySQL</title><content type='html'>The basic commands you must execute to install a *MySQL* source&lt;br /&gt;distribution are:&lt;br /&gt;&lt;br /&gt;     shell&gt; groupadd mysql&lt;br /&gt;     shell&gt; useradd -g mysql mysql&lt;br /&gt;     shell&gt; gunzip &lt; mysql-VERSION.tar.gz | tar -xvf -&lt;br /&gt;     shell&gt; cd mysql-VERSION&lt;br /&gt;     shell&gt; ./configure --prefix=/usr/local/mysql&lt;br /&gt;     shell&gt; make&lt;br /&gt;     shell&gt; make install&lt;br /&gt;     shell&gt; scripts/mysql_install_db&lt;br /&gt;     shell&gt; chown -R root  /usr/local/mysql&lt;br /&gt;     shell&gt; chown -R mysql /usr/local/mysql/var&lt;br /&gt;     shell&gt; chgrp -R mysql /usr/local/mysql&lt;br /&gt;     shell&gt; cp support-files/my-medium.cnf /etc/my.cnf&lt;br /&gt;     shell&gt; /usr/local/mysql/bin/safe_mysqld --user=mysql &amp;amp;&lt;br /&gt;&lt;br /&gt;To start mysqld at boot time you have to copy support-files/mysql.server&lt;br /&gt;to the right place for your system&lt;br /&gt;&lt;br /&gt;PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !&lt;br /&gt;This is done with:&lt;br /&gt;./bin/mysqladmin -u root -p password 'new-password' (note that new-password *IS* the new root password you wanna assign, and initially there is *NO* password for mysql so when it asks for password: just hit ENTER)&lt;br /&gt;./bin/mysqladmin -u root -h server-name -p password 'new-password'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12233913-111373275045025083?l=mysql-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mysql-tips.blogspot.com/feeds/111373275045025083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=12233913&amp;postID=111373275045025083' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373275045025083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12233913/posts/default/111373275045025083'/><link rel='alternate' type='text/html' href='http://mysql-tips.blogspot.com/2005/04/installing-mysql.html' title='Installing MySQL'/><author><name>Tech Journalist</name><uri>http://www.blogger.com/profile/06397377314569093942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
