<?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>Fernandez de Quilon &#187; MySql</title>
	<atom:link href="http://www.jefferyfernandez.id.au/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jefferyfernandez.id.au</link>
	<description>between flat screens and grey matter</description>
	<lastBuildDate>Thu, 04 Aug 2011 23:01:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3-aortic-dissection</generator>
		<item>
		<title>MySQL Date Age Calculation</title>
		<link>http://www.jefferyfernandez.id.au/2008/07/02/mysql-date-age-calculation/</link>
		<comments>http://www.jefferyfernandez.id.au/2008/07/02/mysql-date-age-calculation/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 09:03:03 +0000</pubDate>
		<dc:creator>Jeffery</dc:creator>
				<category><![CDATA[MySql]]></category>
		<category><![CDATA[stored routines]]></category>

		<guid isPermaLink="false">http://www.jefferyfernandez.id.au/?p=76</guid>
		<description><![CDATA[I have always had the need to calculate the age as year and month from a MySQL field of type date. No doubt you can achieve this with a bit of PHP, but when you require to do the conversion &#8230; <a href="http://www.jefferyfernandez.id.au/2008/07/02/mysql-date-age-calculation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have always had the need to calculate the age as year and month from a MySQL field of type date. No doubt you can achieve this with a bit of PHP, but when you require to do the conversion right from MySQL, you can only go as far as getting the age in &#8220;years&#8221;.</p>
<p>I have used here a MySQL stored routine to achive this:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">FUNCTION</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`my<span style="color: #008080; font-weight: bold;">_</span>database`</span>.<span style="color: #008000;">`getage`</span> $$
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DEFINER</span><span style="color: #CC0099;">=</span><span style="color: #008000;">`root`</span>@<span style="color: #008000;">`localhost`</span> <span style="color: #990099; font-weight: bold;">FUNCTION</span> <span style="color: #008000;">`getage`</span><span style="color: #FF00FF;">&#40;</span>pdate <span style="color: #999900; font-weight: bold;">DATE</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">RETURNS</span> <span style="color: #000099;">char</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">30</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">DETERMINISTIC</span>
<span style="color: #990099; font-weight: bold;">BEGIN</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> years <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> months <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> days <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">DECLARE</span> current_year <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> current_month <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> current_day <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">DECLARE</span> year_diff <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> month_diff <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> day_diff <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">DECLARE</span> yearstring <span style="color: #000099;">CHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">6</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">DECLARE</span> monthstring <span style="color: #000099;">CHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">7</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">YEAR</span><span style="color: #FF00FF;">&#40;</span>pdate<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> years<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">MONTH</span><span style="color: #FF00FF;">&#40;</span>pdate<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> months<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">DAY</span><span style="color: #FF00FF;">&#40;</span>pdate<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> days<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">YEAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">CURRENT_DATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> current_year<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">MONTH</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">CURRENT_DATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> current_month<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">DAY</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">CURRENT_DATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> current_day<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #FF00FF;">&#40;</span>current_year <span style="color: #CC0099;">-</span> years<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> year_diff<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #FF00FF;">&#40;</span>current_month <span style="color: #CC0099;">-</span> months<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> month_diff<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #FF00FF;">&#40;</span>current_day <span style="color: #CC0099;">-</span> days<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">INTO</span> day_diff<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">if</span> <span style="color: #FF00FF;">&#40;</span>current_month <span style="color: #CC0099;">&amp;</span>lt<span style="color: #000033;">;</span> months<span style="color: #FF00FF;">&#41;</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">SET</span> month_diff <span style="color: #CC0099;">=</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#40;</span>months <span style="color: #CC0099;">-</span> <span style="color: #008080;">12</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">*</span> <span style="color: #CC0099;">-</span><span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">+</span> current_month<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">SET</span> year_diff <span style="color: #CC0099;">=</span> <span style="color: #FF00FF;">&#40;</span>year_diff <span style="color: #CC0099;">-</span> <span style="color: #008080;">1</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">if</span> <span style="color: #FF00FF;">&#40;</span> month_diff <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">SET</span> monthstring <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;month&quot;</span><span style="color: #000033;">;</span>
<span style="color: #009900;">ELSE</span>
	<span style="color: #990099; font-weight: bold;">SET</span> monthstring <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;months&quot;</span><span style="color: #000033;">;</span>
<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">if</span> <span style="color: #FF00FF;">&#40;</span> year_diff <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #009900;">THEN</span>
	<span style="color: #990099; font-weight: bold;">SET</span> yearstring <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;year&quot;</span><span style="color: #000033;">;</span>
<span style="color: #009900;">ELSE</span>
	<span style="color: #990099; font-weight: bold;">SET</span> yearstring <span style="color: #CC0099;">=</span> <span style="color: #008000;">&quot;years&quot;</span><span style="color: #000033;">;</span>
<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">if</span> <span style="color: #FF00FF;">&#40;</span> year_diff <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #009900;">THEN</span>
	RETURN <span style="color: #000099;">CONCAT_WS</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">' '</span><span style="color: #000033;">,</span> month_diff<span style="color: #000033;">,</span> monthstring<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #009900;">ELSE</span>
	<span style="color: #009900;">if</span> <span style="color: #FF00FF;">&#40;</span>month_diff <span style="color: #CC0099;">&amp;</span>gt<span style="color: #000033;">;</span> <span style="color: #008080;">0</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #009900;">THEN</span>
		RETURN <span style="color: #000099;">CONCAT_WS</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">' '</span><span style="color: #000033;">,</span>year_diff<span style="color: #000033;">,</span> yearstring<span style="color: #000033;">,</span> month_diff<span style="color: #000033;">,</span> monthstring<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #009900;">ELSE</span>
		RETURN <span style="color: #000099;">CONCAT_WS</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">' '</span><span style="color: #000033;">,</span>year_diff<span style="color: #000033;">,</span> yearstring<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #009900;">END</span> $$
&nbsp;
DELIMITER <span style="color: #000033;">;</span></pre></div></div>

<p>You can then make use of the stored routine to convert Dates into ages by doing so:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> getage<span style="color: #FF00FF;">&#40;</span>BirthDate<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">as</span> UserAge <span style="color: #990099; font-weight: bold;">FROM</span> my_database.users</pre></div></div>

<ul>
<li><a title="http://dev.mysql.com/doc/refman/5.0/en/routine-restrictions.html" href="http://dev.mysql.com/doc/refman/5.0/en/routine-restrictions.html" target="_blank">http://dev.mysql.com/doc/refman/5.0/en/routine-restrictions.html</a></li>
<li><a title="http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html" href="http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html" target="_blank">http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html</a></li>
</ul>
<div style="float:left;margin:0px 0px 0px 0px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.jefferyfernandez.id.au/2008/07/02/mysql-date-age-calculation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL Forge is Open</title>
		<link>http://www.jefferyfernandez.id.au/2007/08/13/mysql-forge-is-open/</link>
		<comments>http://www.jefferyfernandez.id.au/2007/08/13/mysql-forge-is-open/#comments</comments>
		<pubDate>Mon, 13 Aug 2007 01:08:06 +0000</pubDate>
		<dc:creator>Jeffery</dc:creator>
				<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://jefferyfernandez.id.au/2007/08/13/mysql-forge-is-open/</guid>
		<description><![CDATA[Use the Forge! The Forge: home of MySQL Community MySQL Forge is the place where MySQL AB, the company behind the popular Open Source Database (MySQL) and the community meet and work together. If you have a cool project? Give &#8230; <a href="http://www.jefferyfernandez.id.au/2007/08/13/mysql-forge-is-open/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Use the Forge!</h2>
<p><strong>The <a href="http://forge.mysql.com/" target="_blank">Forge</a>: home of MySQL Community</strong><br />
<img src="http://www.jefferyfernandez.id.au/wp-content/uploads/2007/08/dolphin_forge.thumbnail.jpg" alt="MySQL Forge" align="left" /><br />
<a href="http://forge.mysql.com/" target="_blank">MySQL Forge</a> is the place where MySQL AB, the company behind the popular Open Source Database (MySQL) and the community meet and work together.</p>
<ul>
<li>If you have a cool project? Give it a home on <a href="http://forge.mysql.com/projects" target="_blank">Projects</a>.</li>
<li>Want to share a cool snippet? Paste it to <a href="http://forge.mysql.com/snippets" target="_blank">Snippets</a>.</li>
<li>Curious about MySQL AB&#8217;s development plans? Browse the <a href="http://forge.mysql.com/worklog" target="_blank">Worklog</a>.</li>
<li>Do you want to share your ideas, contribute to MySQL projects, learn about the internals? Use the <a href="http://forge.mysql.com/wiki" target="_blank">Wiki</a>.</li>
</ul>
<div style="float:left;margin:0px 0px 0px 0px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.jefferyfernandez.id.au/2007/08/13/mysql-forge-is-open/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Database backup script</title>
		<link>http://www.jefferyfernandez.id.au/2007/01/25/mysql-database-backup-script/</link>
		<comments>http://www.jefferyfernandez.id.au/2007/01/25/mysql-database-backup-script/#comments</comments>
		<pubDate>Thu, 25 Jan 2007 06:02:34 +0000</pubDate>
		<dc:creator>Jeffery</dc:creator>
				<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://jefferyfernandez.id.au/2007/01/25/mysql-database-backup-script/</guid>
		<description><![CDATA[This script I have here has saved me a number of times from embarrassment. Many a times I happened to have &#8220;accidently&#8221; dropped an entire database (in phpmyadmin) while wanting to drop only a few tables. Apparently the big-fat &#8220;drop&#8221; &#8230; <a href="http://www.jefferyfernandez.id.au/2007/01/25/mysql-database-backup-script/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This script I have here has saved me a number of times from embarrassment. Many a times I happened to have &#8220;accidently&#8221; dropped an entire database (in phpmyadmin) while wanting to drop only a few tables. Apparently the big-fat &#8220;drop&#8221; button at the top navigation is related to the database than the tables you have selected in the listing.</p>
<p>The script has the ability to dump your database tables and upload them to an ftp server or email the compressed sql file to your email address. I haven&#8217;t written this entirely on my own but with help from various people on discussion forums. Post back your comments and improvements if any.</p>
<p><span id="more-33"></span><br />
<script type="text/javascript"><!--
google_ad_client = "pub-5896900602713932";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-10-07: general
google_ad_channel = "5562041263";
//-->
</script><br />
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<pre class="textinput">
#!/bin/sh

# Get the Day of the Week (Sun-Mon-Tue-Wed-Thu-Fri-Sat)
# This allows to save one backup for each day of the week
DOW=`date +%a`

# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
databases="mphpugt_mambo mphpugt_phpcollab"

# Directory where you want the backup files to be placed
backupDir=/home/mphpugt/databaseBackup

# MySQL dump command, use the full path name here
mysqlDumpCMD=/usr/bin/mysqldump

# MySQL Username and password
userPassword=" --user=[replace with database username] --password=[replace with password]"

# MySQL dump options
dumpOptions=" --opt"

# Unix Commands
gzip=/bin/gzip
uuencode=/usr/bin/uuencode
mail=/bin/mail

# Send Backup?  Would you like the backup emailed to you?
# Set to "y" if you do
emailBackup="y"
subject="Database Backup"
maitTo="admin@techsatcomputers.com"

# Site-specific variables for FTP
ftpBackup="y"
ftpServer=techsatcomputers.com
ftpUser=backup@techsatcomputers.com
ftpPassword=[replace with password]
ftpDir=/

####################### End of Configuration #############################

# Create our backup directory if not already there
mkdir -p ${backupDir}
if [ ! -d ${backupDir} ]
then
   echo "Not a directory: ${backupDir}"
   exit 1
fi

# Dump all of our databases
echo "Dumping MySQL Databases"
for db in $databases
do
  $mysqlDumpCMD $userPassword $dumpOptions $db > ${backupDir}/${DOW}_${db}.sql
done

# Compress all of our backup files
echo "Compressing Dump Files"
for db in $databases
do
  rm -f ${backupDir}/${DOW}_${db}.sql.gz
  $gzip ${backupDir}/${DOW}_${db}.sql
done

# Send the backups via email
if [ $emailBackup = "y" ]
then
echo "Emailing Files to " $maitTo
   for db in $databases
   do
      $uuencode ${backupDir}/${DOW}_${db}.sql.gz ${DOW}_${db}.sql.gz > ${backupDir}/${DOW}_${db}.sql.gz.uu
      size=`wc -c < ${backupDir}/${DOW}_${db}.sql.gz`
      echo "Sending file: ${DOW}_${db}.sql.gz .....Total $size Bytes"
      $mail -s "$subject: ${DOW}_${db} (${size} Bytes)" $maitTo < ${backupDir}/${DOW}_${db}.sql.gz.uu
     rm -f ${backupDir}/${DOW}_${db}.sql.gz.uu
   done
fi

# FTP it to the off-site server
if [ $ftpBackup = "y" ]
then
echo "FTP-ing file to $ftpServer FTP server"
for db in $databases
do
echo "==> ${DOW}_${db}.sql.gz"
ftp -in &lt;&lt;EOF
open $ftpServer
user $ftpUser $ftpPassword
bin
hash
prompt
cd $ftpDir
lcd ${backupDir}
put ${DOW}_${db}.sql.gz
quit
EOF
done
fi

# And we're done
ls -l ${backupDir}
echo "Backup Complete!"
exit
</pre>
<div style="float:left;margin:0px 0px 0px 0px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.jefferyfernandez.id.au/2007/01/25/mysql-database-backup-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Re-setting Mysql root password</title>
		<link>http://www.jefferyfernandez.id.au/2006/05/28/re-setting-mysql-root-password/</link>
		<comments>http://www.jefferyfernandez.id.au/2006/05/28/re-setting-mysql-root-password/#comments</comments>
		<pubDate>Sun, 28 May 2006 05:41:30 +0000</pubDate>
		<dc:creator>Jeffery</dc:creator>
				<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://jefferyfernandez/2006/05/28/re-setting-mysql-root-password/</guid>
		<description><![CDATA[If you have never set a root password for your MySQL database, then the server will not require a password at all for connecting as root. It is recommended to always set a password for each user and more importantly &#8230; <a href="http://www.jefferyfernandez.id.au/2006/05/28/re-setting-mysql-root-password/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have never set a root password for your MySQL database, then the server will not require a password at all for connecting as root. It is recommended to always set a password for each user and more importantly the mysql root user.</p>
<p>On the other hand, If you have set a root password, but forgot what it was, you can set a new password with the following procedure:</p>
<h3> Stop MySql Service</h3>
<p>First we need to stop the running process of the MySql server.<br />
<code class="rootcommand">/etc/init.d/mysqld stop</code><br />
<span id="more-11"></span><br />
<script type="text/javascript"><!--
google_ad_client = "pub-5896900602713932";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-10-07: general
google_ad_channel = "5562041263";
//-->
</script><br />
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>If the above command does not work for you, you will need to find the appropriate comand for your linux distribution. Depending on what type of MySql server you are running, other variants of the init.d script are mysqld-max and mysqld-ndb.</p>
<h3>Start without Grant Tables</h3>
<p>Now we need to start the MySql server without any grant tables. This means the MySql server should be running without any access restrictions.<br />
<code class="rootcommand">mysqld_safe --skip-grant-tables &#038;</code><br />
Once you have got mysql running with the &#8220;&#8211;skip-grant-tables&#8221; option, we now need to login to the mysql server. Open a new shell and type in the following:<br />
<code class="rootcommand">mysql -u root</code><br />
It should now take you to the Mysql prompt:<br />
<code class="mysqlrootcommand">&nbsp;</code><br />
Now lets update the Mysql root users password. In this example I an updating the password to be &#8220;FpS0Fb7W&#8221;:<br />
<code class="mysqlrootcommand">UPDATE mysql.user SET Password = PASSWORD('FpS0Fb7W') WHERE User = 'root';</code></p>
<pre class="shelloutput">
Query OK, 2 rows affected (0.21 sec)
Rows matched: 2  Changed: 2  Warnings: 0
</pre>
<p>Usually you will have more than one set of privileges for your root account. One for localhost access and the other for access from anywhere (%). If you have more than one root user account privilege, it will update both accounts. In order to update only the localhost priviledge, use:<br />
<code class="mysqlrootcommand">UPDATE user SET Password=PASSWORD('YOUR_PASSWORD') WHERE Host='localhost' AND User='root';</code><br />
Now lets reload the Mysql Databases privileges<br />
<code class="mysqlrootcommand">FLUSH PRIVILEGES;</code></p>
<pre class="shelloutput">Query OK, 0 rows affected (0.00 sec)</pre>
<h3>Gotchas</h3>
<p>If you ever happened to get an error (when starting mysql with &#8211;skip-grant-tables) similar to the one shown below:</p>
<pre class="shelloutput">mysql ended</pre>
<p>Then its probabily because there are some permission problems. Shown below is what the mysql error log outputted in that instance.</p>
<pre class="shelloutput">
060519 09:01:39  mysqld started
/usr/sbin/mysqld-max: Can't read dir of '/root/tmp/' (Errcode: 13)
/usr/sbin/mysqld-max: Can't create/write to file '/root/tmp/ibwA6mDj' (Errcode: 13)
060519  9:01:39  InnoDB: Error: unable to create temporary file; errno:13
060519  9:01:39 [ERROR] Can't init databases
060519  9:01:39 [ERROR] Aborting
060519  9:01:39 [Note] /usr/sbin/mysqld-max: Shutdown complete
060519 09:01:40  mysqld ended
</pre>
<p>This basically means that your systems $TMPDIR definition is set to the root directory. To fix, just do the following:<br />
<code class="rootcommand">export TMPDIR=/tmp/</code><br />
This will then set the TMPDIR to the appropriate directory and fixes the error.</p>
<div style="float:left;margin:0px 0px 0px 0px;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.jefferyfernandez.id.au/2006/05/28/re-setting-mysql-root-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

