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

<channel>
	<title>Gudasoft &#187; databases</title>
	<atom:link href="http://www.gudasoft.com/tag/databases/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gudasoft.com</link>
	<description>Impossible is nothing</description>
	<lastBuildDate>Thu, 06 Oct 2011 07:17:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Защитен: Query multiple tables</title>
		<link>http://www.gudasoft.com/english/development/databases-development/12/18/340/query-multiple-tables/2008</link>
		<comments>http://www.gudasoft.com/english/development/databases-development/12/18/340/query-multiple-tables/2008#comments</comments>
		<pubDate>Thu, 18 Dec 2008 09:57:02 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=340</guid>
		<description><![CDATA[Няма откъс, защото публикацията е защитена.]]></description>
			<content:encoded><![CDATA[<form action="http://www.gudasoft.com/wp-pass.php" method="post">
<p>Публикацията е защитена с парола. За да я видите, моля въведете паролата:</p>
<p><label for="pwbox-340">Парола:<br />
<input name="post_password" id="pwbox-340" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Изпращане" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/english/development/databases-development/12/18/340/query-multiple-tables/2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Archiving data &#8211; great article</title>
		<link>http://www.gudasoft.com/english/development/databases-development/12/16/327/archiving-data-great-article/2008</link>
		<comments>http://www.gudasoft.com/english/development/databases-development/12/16/327/archiving-data-great-article/2008#comments</comments>
		<pubDate>Tue, 16 Dec 2008 12:54:44 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=327</guid>
		<description><![CDATA[http://dev.mysql.com/tech-resources/articles/storage-engine.html Some implementation notes: in gentoo you must enable the storage engines in /etc/make.conf USE="unicode big-tables extraengine In debian This article is so valuable to me so I will copy/paste the last part of it here&#8230; Data Archiving Techniques Data archiving, a subset of Information Lifecycle Management (ILM), typically involves horizontally partitioning data so that [...]]]></description>
			<content:encoded><![CDATA[<p>http://dev.mysql.com/tech-resources/articles/storage-engine.html</p>
<p><span id="more-327"></span>Some implementation notes:</p>
<p>in gentoo you must enable the storage engines in /etc/make.conf</p>
<p><code>USE="unicode big-tables extraengine</code></p>
<p>In debian</p>
<p>This article is so valuable to me so I will<span style="color: #ff0000;"> copy/paste </span>the last part of it here&#8230;</p>
<h2>Data Archiving Techniques</h2>
<p>Data archiving, a subset of Information Lifecycle Management (ILM), typically involves horizontally partitioning data so that a set of current information resides in one or more objects, while the historical/archived data is placed in separate objects. Oftentimes, historical data can be transferred to lower-cost storage devices (like <a href="http://www.emc.com/products/family/emc-centera-family.htm">EMC Centera</a>) that allow easy disk access, but provide significant financial savings. Of course, the idea behind data archiving is to lessen response times by reducing the sheer amount of data needed for current access. However, for analytic purposes, there are times when both the current and archive data needs to be accessed together.</p>
<p>For data archiving environments, Archive tables can easily be accessed in standalone fashion or be set up in union views, which is the primary vehicle used to reference both current and archived data in one object. By combining MySQL&#8217;s Archive storage engine with the new 5.0 Federated table support, a DBA can smartly transfer historical data to cheapter storage devices and then reference both current and archived data when needed.</p>
<p>For example, let&#8217;s say you have a set of recent information regarding customer transactions in a transactional InnoDB table called <code>CLIENT_TRANSACTION</code>, and a set of historical transactions stored in an Archive table called <code>CLIENT_TRANSACTION_HIST</code>.  To lessen load on the active server, you can</p>
<ol>
<li>Transfer the history table to another MySQL server that utilizes cheaper storage devices.</li>
<li>Set it up to use the Archive storage engine.</li>
<li>Create a federated table link to the historical data from the current database.</li>
<li>Build a union view to reference both together when needed.</li>
</ol>
<p>On the historical MySQL Server:</p>
<pre>mysql&gt; alter table client_transaction_hist engine=archive;
Query OK, 112050 rows affected, 0 warning (1.98 sec)
Records: 112050  Duplicates: 0  Warnings: 0</pre>
<p>On the MySQL Server that contains active data:</p>
<pre>mysql&gt; select count(*) from client_transaction;
+----------+
| count(*) |
+----------+
|    18675 |
+----------+
1 row in set (0.00 sec)

mysql&gt; CREATE TABLE client_transaction_hist (
    -&gt;   client_transaction_id int(11) NOT NULL,
    -&gt;   client_id int(11) NOT NULL,
    -&gt;   investment_id int(11) NOT NULL,
    -&gt;   action varchar(10) NOT NULL,
    -&gt;   price decimal(12,2) NOT NULL,
    -&gt;   number_of_units int(11) NOT NULL,
    -&gt;   transaction_status varchar(10) NOT NULL,
    -&gt;   transaction_sub_timestamp datetime NOT NULL,
    -&gt;   transaction_comp_timestamp datetime NOT NULL,
    -&gt;   description varchar(200) default NULL,
    -&gt;   broker_id bigint(10) default NULL,
    -&gt;   broker_commission decimal(10,2) default NULL
    -&gt; ) ENGINE=FEDERATED
    -&gt; COMMENT='mysql://mysql:password@serv1:3306/gim/client_transaction_hist';
Query OK, 0 rows affected (0.14 sec)

mysql&gt; CREATE VIEW client_transaction_all as
    -&gt; select * from client_transaction
    -&gt; union all
    -&gt; select * from client_transaction_hist;
Query OK, 0 rows affected (0.08 sec)

mysql&gt; select count(*) from client_transaction_all;
+----------+
| count(*) |
+----------+
|    130725|
+----------+
1 row in set (1.20 sec)</pre>
<p>Note: rather than use a <code>SELECT *</code> in the view definition above, the actual columns should be listed out; the above was only done to save space for this article.</p>
<p>The targets for Archive tables in data warehousing or data archiving environments are fact and summary tables as they usually contain the bulk of the information. Dimension tables are rarely large enough to warrant a switch to Archive.</p>
<h2>Miscellaneous Archive Engine Notes</h2>
<p>We talked earlier about the Archive engine being a good choice for storing data auditing results as only <code>INSERT and SELECT</code> are supported.  Let&#8217;s check to be sure:</p>
<pre>mysql&gt; delete from test_archive where client_id = 50;
ERROR 1031 (HY000): Table storage engine for 'test_archive' doesn't have this option
mysql&gt; update test_archive set price=120 where client_id = 50;
ERROR 1031 (HY000): Table storage engine for 'test_archive' doesn't have this option</pre>
<p>We also talked about how Archive doesn&#8217;t support indexes at this time:</p>
<pre>mysql&gt; create index my_index on test_archive (client_transaction_id);
ERROR 1069 (42000): Too many keys specified; max 0 keys allowed</pre>
<p>One special thing to note about Archive tables and indexes is that, if you want to alter another storage engine table to be an Archive table, you must first drop any indexes that have been defined on the table.</p>
<p>Archive tables are supported by the new <code>sql_mode</code> data integrity enhancements in MySQL 5.0, so you can ensure only proper data finds its way into your Archive tables:</p>
<pre>mysql&gt; create table test (c1 int) engine=archive;
Query OK, 0 rows affected (0.11 sec)

mysql&gt; insert into test values ('hi');
Query OK, 1 row affected, 1 warning (0.05 sec)

mysql&gt; select * from test;
+------+
| c1   |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

mysql&gt; set sql_mode='strict_all_tables';
Query OK, 0 rows affected (0.00 sec)

mysql&gt; insert into test values ('hi');
ERROR 1264 (22003): Out of range value adjusted for column 'c1' at row 1</pre>
<h2>Conclusion</h2>
<p>DBAs facing the problem of corporate data explosion have an excellent new tool to help them in the MySQL 5.0 Archive storage engine. Whether it&#8217;s a data warehousing, data archiving, or data auditing situation, MySQL Archive tables can be just what the doctor ordered when it comes to maintaining large amounts of standard or sensitive information, while keeping storage costs at a bare-bones minimum.</p>
<p><small>Updated: 2005-09-16</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/english/development/databases-development/12/16/327/archiving-data-great-article/2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postgres vs MySQL</title>
		<link>http://www.gudasoft.com/english/development/databases-development/10/29/222/postgres-vs-mysql/2008</link>
		<comments>http://www.gudasoft.com/english/development/databases-development/10/29/222/postgres-vs-mysql/2008#comments</comments>
		<pubDate>Wed, 29 Oct 2008 11:19:12 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=222</guid>
		<description><![CDATA[http://mysqldatabaseadministration.blogspot.com/2007_01_01_archive.html]]></description>
			<content:encoded><![CDATA[<p>http://mysqldatabaseadministration.blogspot.com/2007_01_01_archive.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/english/development/databases-development/10/29/222/postgres-vs-mysql/2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Full Text search with MySQL</title>
		<link>http://www.gudasoft.com/english/development/databases-development/05/25/53/full-text-search-with-mysql/2008</link>
		<comments>http://www.gudasoft.com/english/development/databases-development/05/25/53/full-text-search-with-mysql/2008#comments</comments>
		<pubDate>Sun, 25 May 2008 11:55:05 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=53</guid>
		<description><![CDATA[Goodbye MySQL I was optimistic that I could make http://www.cenite.com, a price monitoring website to use the fulltext search of mysql. Unfortuntly I have found so many drawbacks that I have to leave this idea. The main source for information for me was: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html http://devzone.zend.com/node/view/id/1304#Heading14 At first the speed was wonderfull. I was searching in [...]]]></description>
			<content:encoded><![CDATA[<h2>Goodbye MySQL</h2>
<p>I was optimistic that I could make http://www.cenite.com, a price monitoring website to use the fulltext search of mysql. Unfortuntly I have found so many drawbacks that I have to leave this idea. The main source for information for me was:</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html</p>
<p>http://devzone.zend.com/node/view/id/1304#Heading14</p>
<p>At first the speed was wonderfull. I was searching in 300k&gt; records apx. 350mb. But then I have to surrender. I cant configure mysql to work as I want. I know that If I spend two days to become expert on C/C++ with Unicode I will success but this is not the case. I want working solution.</p>
<p>The resons that make me not to use mysql for searching:</p>
<p>There is no way to change the default operator by default it is OR. You must parse the user query and rewrite it.</p>
<p>I want automaticaly truncation on all my terms.</p>
<p>There is no way to tell MySQL what are characters, and what are not&#8230;..sorry, there are two ways:</p>
<p>1. Touching the sources,</p>
<p>2. Configuring in xmls</p>
<p>No documentation on both. Maybe there is &#8230;somewhere.</p>
<p>If you use the default configuration then you will wonder how you get or not get the required results.</p>
<p>Here is a summary of the comands that I use to tweak my mysql server:</p>
<p>SHOW VARIABLES LIKE &#8216;ft%&#8217;<br />
SET @global.ft_min_word_len=2;<br />
SET @local.ft_min_word_len=2;</p>
<p>But it is better to have those options in my.conf<br />
[mysqld]<br />
ft_min_word_len=3<br />
ft_stopword_file=&#8221;C:\MySQL\stop.txt&#8221;</p>
<p>[myisamchk]<br />
ft_min_word_len=3<br />
ft_stopword_file=&#8221;C:\MySQL\stop.txt&#8221;</p>
<p>To check what characterset is using your mysql:</p>
<p>SHOW VARIABLES LIKE &#8216;character_sets_dir&#8217;;</p>
<p>/usr/share/mysql/charsets | E:MySQL Server 5.1sharecharsets</p>
<p>SHOW VARIABLES LIKE &#8216;characte%&#8217;<br />
After that you need to rebuild your index with one of those commands<br />
slow: REPAIR TABLE products QUICK;<br />
slow: myisamchk &#8211;recover &#8211;ft_min_word_len=3 tbl_name.MYI<br />
fastest: DROP INDEX &#8230;; CREATE INDEX&#8230;.;</p>
<h2>Alternatives</h2>
<p>http://www.sphinxsearch.com/</p>
<p>http://endeca.com/</p>
<p>http://lucene.apache.org/solr/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/english/development/databases-development/05/25/53/full-text-search-with-mysql/2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Everyday SQL statements</title>
		<link>http://www.gudasoft.com/uncategorized/05/20/48/everyday-sql-statements/2008</link>
		<comments>http://www.gudasoft.com/uncategorized/05/20/48/everyday-sql-statements/2008#comments</comments>
		<pubDate>Tue, 20 May 2008 07:29:35 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=48</guid>
		<description><![CDATA[Tools Statistics ajaxMyTop, , phpMyTop show full processlist &#8211; to check which command is currently running on the mysql InoDB monitor, Mysqlreport phpmyadmin OR http://phpminiadmin.sourceforge.net/ CPU load info script http://www.maatkit.org/ SQLite manager &#8211; http://iqk.sourceforge.net/ Status SHOW status where Variable_name like &#8216;Th%&#8217; or Variable_name like &#8216;%Connec%&#8217; ; SHOW [GLOBAL &#124; SESSION] STATUS [LIKE 'pattern' &#124; WHERE [...]]]></description>
			<content:encoded><![CDATA[<h2>Tools</h2>
<ul>
<li>Statistics
<ul>
<li><span id="intelliTxt"><a href="http://sourceforge.net/projects/ajaxmytop/">ajaxMyTop</a></span>, <span id="intelliTxt">, <a href="http://sourceforge.net/projects/phpmytop/">phpMyTop</a> </span></li>
<li>show full processlist &#8211; to check which command is currently running on the mysql</li>
</ul>
</li>
<li><a href="http://hackmysql.com/mysqlreport">InoDB monitor, Mysqlreport</a></li>
<li>phpmyadmin OR http://phpminiadmin.sourceforge.net/</li>
<li>CPU load info <a href="http://www.oreillynet.com/databases/blog/2006/07/measuring_resources_for_a_mysq_1.html">script</a></li>
<li><a href="http://www.maatkit.org/">http://www.maatkit.org/</a></li>
<li>SQLite manager &#8211; http://iqk.sourceforge.net/</li>
</ul>
<h2>Status</h2>
<p>SHOW status where  Variable_name like &#8216;Th%&#8217; or Variable_name like &#8216;%Connec%&#8217; ;<br />
SHOW [GLOBAL | SESSION] STATUS [LIKE 'pattern' | WHERE expr]</p>
<p>Check/Repair tables</p>
<p>mysqlcheck -u root -p***** &#8211;auto-repair &#8211;check &#8211;optimize &#8211;all-databases</p>
<h2>Profiling</h2>
<p>watch -n 0.5 &#8216;mysql -u root -ppass -e &#8220;SHOW FULL PROCESSLIST&#8221; | grep Query&#8217;</p>
<p>http://opendba.blogspot.com/2008/03/mysql-finally-ability-to-traceprofile.html</p>
<pre>mysql&gt; set profiling=1;
mysql&gt; select count(*) from mysql.user;
mysql&gt; show profile;</pre>
<h2>Dump</h2>
<p>pg_dump -U test arachnid_archiv_test &#8211;inserts -h chaos.spider.bg &#8211;encoding=utf8 -f pgsql.sql</p>
<pre>mysqldump -c -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASS -r $tfile --add-drop-table $DB</pre>
<pre>mysqldump -c -h localhost -u system3 system3_production -psomepassword -r system3_production.sql  --add-drop-table $DB</pre>
<h3>Dump for full backup with flushing of the log files</h3>
<p>mysqldump -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASS<br />
&#8211;single-transaction &#8211;all-databases &#8211;delete-master-logs &#8211;flush-logs &#8211;master-data=2<br />
&gt; backup_sunday_1_PM.sql</p>
<h2>Encoding problems</h2>
<p>http://www.hostbulgaria.com/tutorials/mysql-charset-encoding.aspx</p>
<p>SHOW VARIABLES LIKE &#8216;character_set_%&#8217;;<br />
curl -i http://system3.spider.bg</p>
<h2>Creating a database</h2>
<p>create database re_production DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;</p>
<h2>Creating a user</h2>
<p>GRANT ALL PRIVILEGES ON arachnid_production.* TO &#8216;payak&#8217;@'%&#8217; IDENTIFIED BY &#8216;payakpassword&#8217; WITH GRANT OPTION;<br />
GRANT ALL PRIVILEGES ON system3_production.* TO &#8216;payak&#8217;@'%&#8217; IDENTIFIED BY &#8216;payakpassword&#8217; WITH GRANT OPTION;</p>
<p><span><span style="font-size: 12px; font-family: Courier; color: #000088;">mysqladmin -u [user] -h localhost -p password &#8216;[new_password]&#8216;</span></span></p>
<h3>SQL for a table</h3>
<p>SHOW CREATE TABLE tblname;</p>
<h3>mysql tunel to another machine</h3>
<p>ssh  -N -f -l root  -L 0.0.0.0:3307:91.196.240.132:3306  s1<br />
open port 3307 on the local machine to 91.196.240.132:3306 and login into s1 with root</p>
<h3>Replace text</h3>
<p>UPDATE script_histories SET cod_script = replace(cod_script,&#8221;observer.ArchiveObserver(siteId)&#8221;,&#8221;observer.ArchiveObserver(siteId, script_id, owned_source_id)&#8221;);</p>
<h3>Copy from one table to another</h3>
<p>DELETE FROM system3_production.articles;<br />
INSERT INTO system3_production.articles SELECT * FROM arachnid_from_screen.articles;</p>
<h3>Sessions for Rails</h3>
<p>select count(*) from sessions where updated_at &lt; DATE_SUB(now(), INTERVAL 3 DAY);</p>
<h2>Binnary loging</h2>
<p>http://dev.mysql.com/doc/refman/5.0/en/recovery-from-backups.html</p>
<p><a href="http://www.gudasoft.com/wp-content/uploads/2008/10/mysql-replication2585531.pdf">Check this attachment here: mysql-presentation on replication etc.</a></p>
<ul>
<li>See the status of the log files<br />
SHOW BINARY LOGS;<br />
SHOW MASTER STATUS;</li>
<li>Clean the binary logs instantly<br />
RESET MASTER;</li>
<li>Clean binary logs to date/name<br />
PURGE BINARY LOGS TO &#8221;mysqld-bin.00XXXX&#8217;;</li>
<li>Configurations in my.cnf<br />
log-bin<br />
server-id                                       = 1<br />
expire_logs_days = 1<br />
max_binlog_size  = 100M</li>
</ul>
<p>Configuration</p>
<p>max_allowed_packet                      = 50M<br />
wait_timeout=720<br />
max_connections=1000<br />
connect_timeout=20</p>
<p>query_cache_limit=8M            #~~~ removed, 1M def. max pozwl. razmer za cache-hirane na edna zajawka<br />
query_cache_size=128M             #~~~ 32M, 0 def.<br />
query_cache_type=1</p>
<h2>Restoring the maintian Debian User</h2>
<pre>GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '&lt;password&gt;' WITH GRANT OPTION;
Replace &lt;password&gt; with your debian-sys-maint password.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/uncategorized/05/20/48/everyday-sql-statements/2008/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Database migration from cp1251 -&gt; utf8</title>
		<link>http://www.gudasoft.com/uncategorized/04/13/4/database-migration-from-cp1251-utf8/2008</link>
		<comments>http://www.gudasoft.com/uncategorized/04/13/4/database-migration-from-cp1251-utf8/2008#comments</comments>
		<pubDate>Sun, 13 Apr 2008 16:49:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.gudasoft.com/?p=4</guid>
		<description><![CDATA[It was time to migrate http://www.cenite.com database from cp1251 -&#62; utf8, I have prepared one nice script which will show you step by step the commands that you should run in order to migrate your database. Copy the content to cp1251toUTF8.sh or use the commands manually The script is making echo instead of running the [...]]]></description>
			<content:encoded><![CDATA[<p>It was time to migrate http://www.cenite.com database from cp1251 -&gt; utf8, I have prepared one nice script which will show you step by step the commands that you should run in order to migrate your database.</p>
<p>Copy the content to cp1251toUTF8.sh or use the commands manually</p>
<p>The script is making echo instead of running the commands because this will give you a chance to fix an error if occurs.</p>
<pre>#!/bin/bash
echo "Set the params in the script and you will get the commands that you must run in order to get your database converted"

SOURCE_DATABASE=source_database_name
TARGET_DATABASE=new_database_name

USER=router
HOST=mysql.spider.bg

# ----------------------------------- No need to touch bellow
echo -e  "\n\n# Lets export the source database"
echo "mysqldump -u $USER -p -h $HOST --default-character-set=cp1251 --max_allowed_packet=64M $SOURCE_DATABASE &gt; db1.sql"

# recode latin1..utf8 or what ever...
echo -e "\n\n# Lets convert it"
echo "recode -v -f windows-1251..UTF-8 &lt; db1.sql &gt; db2.sql"

echo -e "\n\n# Lets replace some sql creation statements. maybe you will want to do it manually"
echo perl -pi -e "s/cp1251/utf8/g" db2.sql
echo perl -pi -e "s/utf8_bulgarian_ci/utf8_general_ci/g" db2.sql

echo -e "\n\n# Lets create the target database"
echo mysql -u $USER -p -h $HOST mysql -e \"drop database $TARGET_DATABASE\; CREATE DATABASE $TARGET_DATABASE CHARACTER SET utf8 COLLATE utf8_general_ci\";

echo -e "\n\n# Lets do the initial import"
echo "mysql -u $USER -p -h $HOST $TARGET_DATABASE --max_allowed_packet=64M --default-character-set=utf8 &lt; db2.sql"</pre>
<p>As a bonus here is a command with which you can convert an all your html pages to utf8 also</p>
<p><code>find . -name '*.html' -exec recode -v -f windows-1251..UTF-8 \{\} +</code></p>
<p>This would recursively find all htmls in the current directory.</p>
<h1>How to detect character sets</h1>
<p>http://linux.die.net/man/1/enca</p>
<h1>Migrating Latin1 -&gt; UTF8</h1>
<p>We have the mistake to enter all the data in the database (utf8) without setting the right connection encoding (set names utf8). In this case our content is stored as latin1 characters in the utf8 database.</p>
<p>Here is the magic that fixes the encoding found by my bright <span id="query" class="query">colleague</span> bl8cki</p>
<p>alter table articles convert to character set latin1;<br />
alter table articles change content content blob;<br />
alter table articles change title title blob;<br />
alter table articles change author author blob;<br />
alter table articles change content content text character set utf8;<br />
alter table articles change title title text character set utf8;<br />
alter table articles change author author text character set utf8;</p>
<p>here is an example</p>
<pre class="wiki">mysql&gt; CREATE TABLE `articles` (`id` int(11) NOT NULL auto_increment,   `title` mediumtext, PRIMARY KEY  (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=10313630 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; set names latin1;
Query OK, 0 rows affected (0.00 sec)

mysql&gt;  insert into articles (title) values('закъсал');
Query OK, 1 row affected (0.00 sec)

mysql&gt; alter table articles convert to character set latin1;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql&gt; alter table articles change title title blob;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql&gt; alter table articles change title title text character set utf8;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql&gt; set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; select * from articles;
+----------+----------------+
| id       | title          |
+----------+----------------+
| 10313630 | закъсал        |
+----------+----------------+
1 row in set (0.00 sec)</pre>
<p>As the example shows it works with cyrilic (pasted in utf8) !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/uncategorized/04/13/4/database-migration-from-cp1251-utf8/2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

