<?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>tech stuff &#187; mysql</title>
	<atom:link href="http://codytaylor.org/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL SUM() Doesn&#8217;t Play Well With Floats</title>
		<link>http://codytaylor.org/2009/10/mysql-sum-doesnt-play-well-with-floats.html</link>
		<comments>http://codytaylor.org/2009/10/mysql-sum-doesnt-play-well-with-floats.html#comments</comments>
		<pubDate>Wed, 28 Oct 2009 00:43:11 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[mysql query]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[round]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sum]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14302</guid>
		<description><![CDATA[Apparently floats and doubles use floating point math, which deals with approximate values for numbers and can thus result in confusion like this. It seems that it isn't really possible to store 0.1 in a column of type float. You can only store 0.00999999977648258.]]></description>
			<content:encoded><![CDATA[<p>I had to write some reports for some legacy software today and I was unpleasantly surprised with the results of my SQL queries. I was selecting dollar values and summing them to for the monthly spending of certain individuals. Easy enough right? I wrote a query something like this :<br />
<pre><code>
SELECT SUM(t.money_spent) as sum_of_spent,
c.customer_name 
from transactions t 
join customers c on t.customer_id=c.customer_id 
group by customer_name order by c.customer_name asc
</code></pre><br />
I ended up getting numerical values that were 10 decimal places long with seemingly random numbers. After checking to make sure the database didn&#8217;t have any odd entries I stumbled on this <a href='http://bugs.mysql.com/bug.php?id=1961' title='bug report'>bug report</a>.<br />
The &#8216;money_spent&#8217; column had a data type of float, which is a waste, but I still don&#8217;t think that it should sum up incorrectly. When I select individual values I get proper two decimal results.<br />
Apparently floats and doubles use floating point math, which deals with approximate values for numbers and can thus result in confusion like this. It seems that it isn&#8217;t really possible to store 0.1 in a column of type float. You can only store 0.00999999977648258. This behavior is a little silly but easily fixed by using the ROUND() function :<br />
<pre><code>
SELECT SUM(ROUND(t.money_spent)) as sum_of_money_spent,
c.customer_name from transactions t 
join customers c on t.customer_id=c.customer_id 
group by customer_name order by c.customer_name asc
</code></pre></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F10%2Fmysql-sum-doesnt-play-well-with-floats.html&amp;linkname=MySQL%20SUM%28%29%20Doesn%26%238217%3Bt%20Play%20Well%20With%20Floats"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/10/mysql-sum-doesnt-play-well-with-floats.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Search the wordpress content management system database</title>
		<link>http://codytaylor.org/2009/10/search-the-wordpress-content-management-system-database.html</link>
		<comments>http://codytaylor.org/2009/10/search-the-wordpress-content-management-system-database.html#comments</comments>
		<pubDate>Thu, 22 Oct 2009 01:29:36 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[content management system]]></category>
		<category><![CDATA[mysql query]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[wordpress database]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14299</guid>
		<description><![CDATA[SQL queries to search and replace posts from a wordpress mysql database.]]></description>
			<content:encoded><![CDATA[<p>Wordpress is by far the most popular content management system for blog hosting. The wordpress content management system uses the mysql database. If you have a big site with a large number of posts then it can be handy to search the content of every post to find certain text. Sometimes you may even need to replace certain keywords with other keywords. As with most content management setups there is probably a plugin that will do just that, but it is far easier to just use basic sql if you know the structure of the wordpress database.<br />
Within either phpmyadmin or mysqlyog (depending on what you are using) you can use this sql query to find the text that you are looking for:<br />
<pre><code>
select * from wp_posts where post_content 
like &#039;%content management system%&#039;;
</code></pre><br />
The ID that you get back is basically the page id. For example, if I query my database and get back an id of 13449 then that content will reside at http://codytaylor.org/?p=13449. Other useful columns are the post_content which is the content text of the post, post_name which is the title of the post, and the guid which is the full url (before mod_rewrite changes it) so you don&#8217;t have to copy and paste the id and append it to your url.</p>
<p>If you need to search and replace some text in more than one post then you can use this sql :<br />
<pre><code>
UPDATE wp_posts SET post_content = REPLACE (
post_content, &#039;content management system&#039;, &#039;CMS&#039;);
</code></pre><br />
That SQL query will replace the &#8216;content management system&#8217; with &#8216;CMS&#8217;.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F10%2Fsearch-the-wordpress-content-management-system-database.html&amp;linkname=Search%20the%20wordpress%20content%20management%20system%20database"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/10/search-the-wordpress-content-management-system-database.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reset Mysql Root Password On Linux</title>
		<link>http://codytaylor.org/2009/10/reset-mysql-root-password-on-linux.html</link>
		<comments>http://codytaylor.org/2009/10/reset-mysql-root-password-on-linux.html#comments</comments>
		<pubDate>Thu, 08 Oct 2009 01:19:03 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[reset mysql root password]]></category>
		<category><![CDATA[reset password]]></category>
		<category><![CDATA[reset root password]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14294</guid>
		<description><![CDATA[If you have root access to a linux server and you don't have the root mysql password, but need it..]]></description>
			<content:encoded><![CDATA[<p>If you have root access to a linux server and you don&#8217;t have the root mysql password, but need it, then you can easily reset the root mysql password in just a few commands. These commands probably differ depending on what linux distro you use. I was using Ubuntu 9.04 (Jaunty Jackalope) when I wrote this.</p>
<p>Firstly you will want to turn the mysql service off.<br />
<pre><code>
codytaylor@server:~$ sudo /etc/init.d/mysql stop
 * Stopping MySQL database server mysqld&nbsp;&nbsp; 
</code></pre><br />
Now we restart the mysql server with the &#8217;skip-grant-tables&#8217; option which basically allows anyone to do whatever they like. It&#8217;s usually preferable to include the &#8217;skip-networking&#8217; option so that only localhost (you) have access to the naked database.<br />
<pre><code>
 codytaylor@server:~$ sudo mysqld_safe --skip-grant-tables --skip-networking &amp;
</code></pre><br />
Now all that is left is actually changing the root password. Log into the mysql monitor and change the root password.<br />
<pre><code>
codytaylor@server:~$ mysql -u root mysql
mysql&gt; UPDATE user SET Password=PASSWORD(&#039;password&#039;) WHERE User=&#039;root&#039;;
mysql&gt; FLUSH PRIVILEGES;
</code></pre><br />
Those commands will reset the root mysql password to &#8216;password&#8217;. Now you&#8217;ll probably want to restart the mysql service and have it run normally.<br />
<pre><code>
codytaylor@server:~$ sudo /etc/init.d/mysql restart
</code></pre></p>
<p>If you are using windows and you want to reset the mysql root password then check the <a href='http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html' title='mysql documentation'>mysql documentation</a>.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F10%2Freset-mysql-root-password-on-linux.html&amp;linkname=Reset%20Mysql%20Root%20Password%20On%20Linux"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/10/reset-mysql-root-password-on-linux.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automated MySQL Install On Windows</title>
		<link>http://codytaylor.org/2009/08/automated-msi-mysql-install-on-windows.html</link>
		<comments>http://codytaylor.org/2009/08/automated-msi-mysql-install-on-windows.html#comments</comments>
		<pubDate>Wed, 19 Aug 2009 02:10:34 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[hands free]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14232</guid>
		<description><![CDATA[Install MySQL with an automated windows batch file.]]></description>
			<content:encoded><![CDATA[<p>If you need to install MySQL databases on a number of machines with roughly the same configuration then it becomes extremely tedious to run the installer wizard on each machine. You can download the MySQL server as a msi package which allows you to install with the MSIEXEC DOS command in windows hands free. To install all the necessary files for MySQL to run you need to type this command at the console:</p>
<p>msiexec /qn /i mysql-essential-5.1.37-win32.msi INSTALLDIR=C:\MySQL</p>
<p>The &#8216;/qn&#8217; switch makes this install quiet. In this example I chose &#8216;C:\MySQL&#8217; as the install directory. Feel free to replace that path with whatever you choose. </p>
<p>Just because MySQL is installed and has all the appropriate files registered doesn&#8217;t mean that it&#8217;s useful. You will probably want it to run as a service, have it listen on a certain port, and have a root user already set up. This can be done with the MySQLInstanceConfig.exe program, although the arguments are a little more involved.<br />
<pre><code>
C:\MySQL\bin\MySQLInstanceConfig.exe -i -q 
&quot;-lC:\MySQL\mysql_install_log.txt&quot; 
&quot;-pC:\MySQL\bin&quot; &quot;-tC:\MySQL\my-template.ini&quot; 
&quot;-cC:\MySQL\my.ini&quot; -v5.1.37 
ServerType=DEVELOPMENT 
DatabaseType=MIXED 
ConnectionUsage=DSS 
Port=3306 
ServiceName=MySQL
RootPassword=root1234 
SkipNetworking=no 
AddBinToPath=yes
</code></pre></p>
<p>The entire string above must be run as one line. If you just copy and paste then the console will error out. Most of the arguments above are straight forward if you&#8217;ve ever configured a MySQL server before but just in case I&#8217;ve detailed the parameters below.<br />
</p>
<p>-n product name<br />
-p path of installation (no \bin)<br />
-v version</p>
<p>Actions:<br />
-i (install instance)<br />
-r (remove instance)<br />
-s (stop instance)<br />
-q (be quiet)<br />
-lfilename (write log file)</p>
<p>When launched manually, these can also be submitted<br />
-t<.cnf template filename><br />
-c<.cnf filename></p>
<p>Use the following options to define the parameters for the configuration file generation.<br />
ServiceName=$<br />
AddBinToPath={yes | no}<br />
ServerType={DEVELOPMENT | SERVER | DEDICATED}<br />
DatabaseType={MIXED | INNODB | MYISAM}<br />
ConnectionUsage={DSS | OLTP}<br />
ConnectionCount=#<br />
SkipNetworking={yes | no}<br />
Port=#<br />
StrictMode={yes | no}<br />
Charset=$<br />
RootPassword=$<br />
RootCurrentPassword=$ </p>
<p>So if you use the example above you will get a basic mysql installation. When I used these commands I put them in a batch file followed by this command:</p>
<p>
mysql &#8211;user=user_name &#8211;password=your_password db_name < create_database_and_tables.sql</p>
<p>The &#8216;create_database_and_tables.sql&#8217; obviously has all the sql code to create the MySQL databases and tables that are needed. The batch file installed, configured, and structured my MySQL databases. I spent awhile yesterday looking for a post like this so hopefully this saves someone some time.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F08%2Fautomated-msi-mysql-install-on-windows.html&amp;linkname=Automated%20MySQL%20Install%20On%20Windows"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/08/automated-msi-mysql-install-on-windows.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

