<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
>

<channel>
<title><![CDATA[Dobrica Pavlinušić's random unstructured stuff: mysql]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?action=weblog_display;category=mysql</link>
<description></description>
<pubDate>Thu, 22 Apr 2010 11:45:31 -0000</pubDate>
<webMaster>root@saturn.ffzg.hr</webMaster>
<generator>Socialtext Workspace v2.19.0.2</generator>

<item>
<title><![CDATA[MySQL]]></title>
<link>https://saturn.ffzg.hr/rot13/index.cgi?mysql</link>
<description><![CDATA[<div>Creator: Dobrica Pavlinušić</div><hr/><div>Tags: mysql</div><hr/><div class="wiki">
<p>
I don't like MySQL for various resons, most important one being that I saw PostgreSQL early on and never looked back.</p>
<p>
Here are few quick commands to ease my pain:</p>
<div class="nlw_phrase"><table class="wafl_container">
  <tr>
    <td>
      <div class="wafl_box">
        
          <div class="wafl_titlebox">
            <div class="wafl_title">
              
                Contents: [Dobrica Pavlinušić's random unstructured stuff]
              
            </div>
          </div>
          <div class="wafl_items">
            
              <div class="wiki">
<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#number_of_rows_in_table">Dobrica Pavlinušić's random unstructured stuff (Number of rows in table)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Number of rows in table} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#create_grepable_dump">Dobrica Pavlinušić's random unstructured stuff (Create grepable dump)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Create grepable dump} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#poor_man_s_graphs">Dobrica Pavlinušić's random unstructured stuff (Poor man's graphs)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Poor man's graphs} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#mysql_koha_utf_8_encoding">Dobrica Pavlinušić's random unstructured stuff (MySQL Koha utf-8 encoding)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] MySQL Koha utf-=8 encoding} --></span></li>

<ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#connect">Dobrica Pavlinušić's random unstructured stuff (connect)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] connect} --></span></li>
</ul>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#my_cnf_performance_optimization">Dobrica Pavlinušić's random unstructured stuff (my.cnf performance optimization)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] my.cnf performance optimization} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#performance_monitoring">Dobrica Pavlinušić's random unstructured stuff (Performance monitoring)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Performance monitoring} --></span></li>
<li><span class="nlw_phrase"><a title="section link" href="https://saturn.ffzg.hr/rot13/index.cgi?dobrica_pavlinu%C5%A1i%C4%87_s_random_unstructured_stuff#linux_tuning">Dobrica Pavlinušić's random unstructured stuff (Linux tuning)</a><!-- wiki: {link: [Dobrica Pavlinušić's random unstructured stuff] Linux tuning} --></span></li>
</ul>
</div>

            
            
          </div>
        
      </div>
    </td>
  </tr>
</table>
<!-- wiki: {toc: }
--></div><br /><br /><h1 id="number_of_rows_in_table">Number of rows in table</h1>
<p>
<tt>select count(*) from table_name</tt> is terrably slow in MySQL, so use <a target="_blank" title="(external link)" href="http://dev.mysql.com/doc/refman/5.1/en/tables-table.html">information schema<!-- wiki-renamed-hyperlink "information schema"<http://dev.mysql.com/doc/refman/5.1/en/tables=-table.html> --></a> to quickly have report...</p>
<pre>
mysql&gt; select table_name,table_rows,avg_row_length,data_length
 from information_schema.tables
 where table_type = 'BASE TABLE'
 order by table_rows desc
 limit 10 ;
+-----------------+------------+----------------+-------------+
| table_name      | table_rows | avg_row_length | data_length |
+-----------------+------------+----------------+-------------+
| zebraqueue      |    2309022 |             87 |   200998912 | 
| sessions        |    1744788 |            675 |  1178402816 | 
| items           |     302540 |            126 |    38338560 | 
| biblio          |     268391 |            166 |    44646400 | 
| action_logs     |     225797 |            341 |    77168640 | 
| biblioitems     |     220004 |           8159 |  1795080192 | 
| items_print_log |     205559 |            104 |    21528576 | 
| statistics      |     130166 |             76 |     9977856 | 
| old_issues      |      43852 |             84 |     3686400 | 
| import_biblios  |      19352 |            136 |     2637824 | 
+-----------------+------------+----------------+-------------+
10 rows in set (1.90 sec)
</pre>
<br /><h1 id="create_grepable_dump">Create grepable dump</h1>
<p>
Put every value in it's own line</p>
<pre>
mysqldump -u user -p database --extended-insert=0 &gt; dump.sql
</pre>
<br /><h1 id="poor_man_s_graphs">Poor man's graphs</h1>
<pre>
mysql&gt; select dateenrolled,count(*),rpad('',count(*) / 10,'*') from borrowers group by dateenrolled;
+--------------+----------+----------------------------------------------+
| dateenrolled | count(*) | rpad('',count(*) / 10,'*')                   |
+--------------+----------+----------------------------------------------+
| NULL         |       18 | **                                           | 
| 2008-04-03   |        1 |                                              | 
| 2008-04-17   |        1 |                                              | 
| 2008-05-28   |        1 |                                              | 
| 2008-06-05   |        1 |                                              | 
| 2008-06-12   |        3 |                                              | 
| 2008-07-28   |        1 |                                              | 
| 2008-10-17   |        1 |                                              | 
| 2008-10-20   |        1 |                                              | 
| 2008-10-21   |        1 |                                              | 
| 2008-10-27   |       11 | *                                            | 
| 2008-10-28   |        2 |                                              | 
| 2008-10-29   |        4 |                                              | 
| 2008-10-30   |        2 |                                              | 
| 2008-11-03   |        1 |                                              | 
| 2008-11-04   |        9 | *                                            | 
| 2008-11-06   |        7 | *                                            | 
| 2008-11-10   |       16 | **                                           | 
| 2008-11-11   |        1 |                                              | 
| 2008-11-13   |        1 |                                              | 
| 2008-11-14   |        4 |                                              | 
| 2008-11-17   |        1 |                                              | 
| 2008-11-20   |        1 |                                              | 
| 2008-11-26   |        1 |                                              | 
| 2008-12-02   |        1 |                                              | 
| 2008-12-19   |        2 |                                              | 
| 2009-01-07   |        2 |                                              | 
| 2009-03-16   |      301 | ******************************               | 
| 2009-03-17   |      365 | *************************************        | 
| 2009-03-18   |      439 | ******************************************** | 
| 2009-03-19   |      324 | ********************************             | 
| 2009-03-20   |      226 | ***********************                      | 
| 2009-03-23   |      105 | ***********                                  | 
+--------------+----------+----------------------------------------------+
33 rows in set (0.00 sec)
</pre>
<br /><h1 id="mysql_koha_utf_8_encoding">MySQL Koha utf-8 encoding</h1>
<h2 id="connect">connect</h2>
<pre>
use DBI();

my $dbh = DBI-&gt;connect ('dbi:mysql:test_db', $username, $password, 
   {mysql_enable_utf8 =&gt; 1}
);
</pre>
<br /><h1 id="my_cnf_performance_optimization">my.cnf performance optimization</h1>
<ul>
<li><a target="_blank" title="(external link)" href="https://launchpad.net/mysql-tuning-primer">https://launchpad.net/mysql-tuning-primer</a></li>
<li><a target="_blank" title="(external link)" href="https://launchpad.net/mysqltuner/">https://launchpad.net/mysqltuner/</a></li>
<li><a target="_blank" title="(external link)" href="http://github.com/rackerhacker/MySQLTuner-perl">http://github.com/rackerhacker/MySQLTuner-perl</a></li>
</ul>
<h1 id="performance_monitoring">Performance monitoring</h1>
<pre>
./mk-query-digest --processlist localhost --interval 0.01
</pre>
<br /><h1 id="linux_tuning">Linux tuning</h1>
<pre>
# turn off readahead
hdparm -a 0 /dev/sdb

# noop/deadline better than cfq
echo noop &gt; /sys/block/sdb/queue/scheduler
</pre>
</div>
]]></description>
<author>Dobrica Pavlinu&#x161;i&#x107;</author>
<category>mysql</category>
<guid isPermaLink="true">https://saturn.ffzg.hr/rot13/index.cgi?mysql</guid>
<pubDate>Thu, 22 Apr 2010 11:45:31 -0000</pubDate>
</item>
</channel>
</rss>