<?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-3043709</id><updated>2012-02-11T20:15:26.262-08:00</updated><category term='splunk'/><category term='firefox'/><category term='mysql FAQ'/><category term='php tips'/><category term='shell script'/><category term='open office'/><category term='mysql'/><category term='python'/><category term='mysql tips'/><category term='php'/><category term='redis'/><category term='sqlite'/><category term='drupal'/><category term='linux tips'/><category term='pear'/><category term='unicode'/><category term='aws'/><category term='mysql 5.1'/><category term='unix case study'/><category term='noSQL'/><category term='usability'/><category term='mysql bug'/><category term='InnoDB'/><category term='mysql case study'/><title type='text'>Shantanu's Blog</title><subtitle type='html'>&lt;b&gt; Corporate Consultant &lt;/b&gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default?start-index=101&amp;max-results=100'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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>686</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3043709.post-5899644693388823915</id><published>2012-02-11T19:16:00.000-08:00</published><updated>2012-02-11T20:15:26.370-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aws'/><title type='text'>aws command prompt</title><content type='html'>In order to use S3 and ec2 Simple Command-Line Access to AWS we need to install an utility:&lt;br /&gt;&lt;br /&gt;http://aws.amazon.com/developertools/Amazon-SimpleDB/739&lt;br /&gt;&lt;br /&gt;Here are the steps to follow. This will help to manage the buckets using command prompt and there is no need to use the web console.&lt;br /&gt;&lt;br /&gt;curl https://raw.github.com/timkay/aws/master/aws -o aws&lt;br /&gt;chmod +x aws&lt;br /&gt;vi ~/.awssecret&lt;br /&gt;(type key and secret key)&lt;br /&gt;chmod go-rwx ~/.awssecret&lt;br /&gt;&lt;br /&gt;perl aws --install&lt;br /&gt;&lt;br /&gt;s3mkdir shantanuo_BUCKET_NAME&lt;br /&gt;s3put shantanuo_BUCKET_NAME test.txt&lt;br /&gt;s3ls shantanuo_BUCKET_NAME&lt;br /&gt;s3get shantanuo_BUCKET_NAME/test.txt&lt;br /&gt;s3delete shantanuo_BUCKET_NAME/test.txt&lt;br /&gt;s3delete shantanuo_BUCKET_NAME&lt;br /&gt;&lt;br /&gt;ec2run&lt;br /&gt;ec2din --simple&lt;br /&gt;ec2tin INSTANCEID&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5899644693388823915?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5899644693388823915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5899644693388823915&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5899644693388823915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5899644693388823915'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/02/aws-command-prompt.html' title='aws command prompt'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-272157165245473577</id><published>2012-02-11T01:03:00.001-08:00</published><updated>2012-02-11T01:04:43.750-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aws'/><title type='text'>AWS product stack</title><content type='html'>Here is the list of tabs those I can see when I log in. I am not impressed by most of them, but EC2, RDS and DynamoDB will prove miracles in the hosting world.&lt;br /&gt;&lt;br /&gt;Elastic Beanstalk:  makes it even easier to deploy and manage scalable applications on the AWS cloud, while retaining the ability to control the underlying resources. &lt;br /&gt;&lt;br /&gt;S3: Buckets to store data that can also be shared on the net.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;EC2&lt;/span&gt;: Start or terminate different type of virtual servers.&lt;br /&gt;&lt;br /&gt;VPC: Virtual Private cloud for your EC2 resources.&lt;br /&gt;&lt;br /&gt;CloudWatch: monitors operational and performance metrics for your AWS cloud resources and applications.&lt;br /&gt;&lt;br /&gt;Elastic MapReduce: Creating a job flow to process your data in a simple and quick way.&lt;br /&gt;&lt;br /&gt;CloudFront: Allow public access to your S3 buckets&lt;br /&gt;&lt;br /&gt;CloudFormation: pre installed Drupal, Joomla or wordpress &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;RDS&lt;/span&gt;: hosted Relational Database Systems like MySQL / Oracle&lt;br /&gt;&lt;br /&gt;ElastiCache: a web service that makes it easier to launch, manage, and scale a distributed in-memory cache in the cloud.&lt;br /&gt;&lt;br /&gt;SQS: Simple Queue Service offers a reliable, highly scalable, hosted queue for storing messages as they travel between applications.&lt;br /&gt;&lt;br /&gt;IAM: Identity and Access Management (IAM) enables you to manage Users, groups and permissions within your AWS account.&lt;br /&gt;&lt;br /&gt;SNS: Simple Notification Service (SNS) is a web service that makes it easy to set up, operate, and send notifications in the cloud.&lt;br /&gt;&lt;br /&gt;SES: Simple Email Service (SES) allows you to send emails.&lt;br /&gt;&lt;br /&gt;Route 53: Allows you to manage your domain name and sub-domains.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;DynamoDB&lt;/span&gt;: a fully managed non-relational fast database service that comes with seamless scalability.&lt;br /&gt;&lt;br /&gt;Storage Gateway: An on-premises virtual appliance that provides seamless and secure integration between your appliances and AWS's storage infrastructure.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-272157165245473577?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/272157165245473577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=272157165245473577&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/272157165245473577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/272157165245473577'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/02/aws-product-stack.html' title='AWS product stack'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1558380695926819871</id><published>2012-02-10T19:41:00.000-08:00</published><updated>2012-02-10T20:32:02.583-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='aws'/><category scheme='http://www.blogger.com/atom/ns#' term='noSQL'/><title type='text'>Import, Export and SQLize DynamoDB</title><content type='html'>You can use Hive to export data from DynamoDB to S3 bucket using Hadoop &lt;br /&gt;&lt;br /&gt;In order to use hadoop, you need Elastic MapReduce instance. Click on "Create New Job Flow" and use defauls to create a new job called "My Job Flow". You will now get the Master Public DNS Name to connect to using "hadoop" as username. Once connected, type "hive" to get the command prompt where you can link to DynamoDB table.&lt;br /&gt;&lt;br /&gt;hive&gt; CREATE EXTERNAL TABLE hivereply (col1 string, col2 string, col3 string, col4 string)&lt;br /&gt;    STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler' &lt;br /&gt;    TBLPROPERTIES ("dynamodb.table.name" = "reply", &lt;br /&gt;    "dynamodb.column.mapping" = "col1:Id,col2:ReplyDateTime,col3:Message,col4:PostedBy");                   &lt;br /&gt;&lt;br /&gt;You can now use the table hivereply just like any other MySQL table. For e.g.&lt;br /&gt;hive&gt; select * from hivereply where col2 = '2012-01-31 23:09:46';&lt;br /&gt;&lt;br /&gt;Amazon DynamoDB#DynamoDB Thread 2       2012-01-31 23:09:46     null&lt;br /&gt;&lt;br /&gt;You can call the INSERT OVERWRITE command to write the data to an external directory. You can use this to create an archive of your Amazon DynamoDB data in Amazon S3.&lt;br /&gt;                        &lt;br /&gt;hive&gt; INSERT OVERWRITE DIRECTORY 's3://php-sdk-getting-started-aki-19/' SELECT * FROM hiveTableName;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1558380695926819871?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1558380695926819871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1558380695926819871&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1558380695926819871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1558380695926819871'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/02/import-export-and-sqlize-dynamodb.html' title='Import, Export and SQLize DynamoDB'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5550234521675085833</id><published>2012-02-10T07:59:00.000-08:00</published><updated>2012-02-10T21:36:09.581-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='aws'/><category scheme='http://www.blogger.com/atom/ns#' term='noSQL'/><title type='text'>Using Comparision Operator in dynamodb</title><content type='html'>If you want to query the data, you need to index it on Range key. For e.g. in the following "reply" table we have a primary key that is combination of Hash key and a Range key. Range key is nothing but the timestamp as on the reply was received. We can write a query that will return all the replies those are older than 7 days.&lt;br /&gt;In this case the column "ReplyDateTime" column is indexed and we can use Comparison Operator.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;require_once 'sdk.class.php';&lt;br /&gt;&lt;br /&gt;$ten_days_ago = date('Y-m-d H:i:s', strtotime("-10 days"));&lt;br /&gt;&lt;br /&gt;// Instantiate the class&lt;br /&gt;$dynamodb = new AmazonDynamoDB();&lt;br /&gt;&lt;br /&gt;$add_response = $dynamodb-&gt;put_item(array(&lt;br /&gt;    'TableName' =&gt; 'reply',&lt;br /&gt;    'Item' =&gt; array(&lt;br /&gt;        'Id'            =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'Amazon DynamoDB#DynamoDB Thread 2' ), // Hash Key&lt;br /&gt;        'ReplyDateTime' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; $ten_days_ago                        ), // Range Key&lt;br /&gt;        'Message'       =&gt; array( AmazonDynamoDB::TYPE_STRING  =&gt; 'DynamoDB Thread 2 Reply 1 text'   ),&lt;br /&gt;        'PostedBy'      =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'User A'                            ),&lt;br /&gt;    )&lt;br /&gt;));&lt;br /&gt;&lt;br /&gt;// Success?&lt;br /&gt;print_r($add_response);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$seven_days_ago = date('Y-m-d H:i:s', strtotime("-7 days"));&lt;br /&gt;&lt;br /&gt;$response = $dynamodb-&gt;query(array(&lt;br /&gt;    'TableName' =&gt; 'reply',&lt;br /&gt;    'HashKeyValue' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'Amazon DynamoDB#DynamoDB Thread 2' ),&lt;br /&gt;// optional parameters&lt;br /&gt;    'AttributesToGet' =&gt; array( 'ReplyDateTime', 'Message', 'PostedBy' ),&lt;br /&gt;    'ConsistentRead' =&gt; true,&lt;br /&gt;    'RangeKeyCondition' =&gt; array(&lt;br /&gt;        'ComparisonOperator' =&gt; AmazonDynamoDB::CONDITION_LESS_THAN_OR_EQUAL,&lt;br /&gt;        'AttributeValueList' =&gt; array(&lt;br /&gt;            array( AmazonDynamoDB::TYPE_STRING =&gt; $seven_days_ago )&lt;br /&gt;        )&lt;br /&gt;    )&lt;br /&gt;));&lt;br /&gt;&lt;br /&gt;// 200 response indicates Success&lt;br /&gt;print_r($response);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5550234521675085833?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5550234521675085833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5550234521675085833&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5550234521675085833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5550234521675085833'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/02/using-comparision-operator-in-dynamodb.html' title='Using Comparision Operator in dynamodb'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7116412231006352940</id><published>2012-02-10T04:42:00.000-08:00</published><updated>2012-02-10T21:34:49.985-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='aws'/><category scheme='http://www.blogger.com/atom/ns#' term='noSQL'/><title type='text'>NoSQL support by AWS</title><content type='html'>Click on "Create Table" button on "DynamoDB" tab while using AWS web Management Console. &lt;br /&gt;&lt;br /&gt;https://console.aws.amazon.com/dynamodb/home&lt;br /&gt;&lt;br /&gt;Type table name "testme1" and choose Number as Primary Key Type. Hash attribute name can be "Id". Assuming that you have correctly installed AWS SDK, the following PHP code should add a key - value to the table testme1 table.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;require_once 'sdk.class.php';&lt;br /&gt;&lt;br /&gt;// Instantiate the class&lt;br /&gt;$dynamodb = new AmazonDynamoDB();&lt;br /&gt;&lt;br /&gt;$add_response = $dynamodb-&gt;put_item(array(&lt;br /&gt;    'TableName' =&gt; 'reply',&lt;br /&gt;    'Item' =&gt; array(&lt;br /&gt;        'Id' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'Amazon DynamoDB#DynamoDB Thread 2' ), // Hash Key&lt;br /&gt;        'ReplyDateTime' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; '2012-01-31 23:28:40' ), // Range Key&lt;br /&gt;        'Message' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'DynamoDB Thread 2 Reply 1 text' ),&lt;br /&gt;        'PostedBy' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'User A' ),&lt;br /&gt;    )&lt;br /&gt;));&lt;br /&gt;&lt;br /&gt;// Success?&lt;br /&gt;print_r($add_response);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;get item is obviously similar to put_item as shown above:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$get_response = $dynamodb-&gt;get_item(array(&lt;br /&gt;    'TableName' =&gt; 'reply',&lt;br /&gt;    'Key' =&gt; array(&lt;br /&gt;        'HashKeyElement' =&gt; array( AmazonDynamoDB::TYPE_STRING =&gt; 'Amazon DynamoDB#DynamoDB Thread 2' )&lt;br /&gt;    )&lt;br /&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;In order to drop the table, use the following:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$delete_response = $dynamodb-&gt;delete_table(array(&lt;br /&gt;    'TableName' =&gt; 'reply'&lt;br /&gt;    )&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;The following code will create a table called "reply":&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$create_response = $dynamodb-&gt;create_table(array(&lt;br /&gt;    'TableName' =&gt; 'reply',&lt;br /&gt;    'KeySchema' =&gt; array(&lt;br /&gt;        'HashKeyElement' =&gt; array(&lt;br /&gt;            'AttributeName' =&gt; 'Id',&lt;br /&gt;            'AttributeType' =&gt; AmazonDynamoDB::TYPE_STRING&lt;br /&gt;        ),&lt;br /&gt;        'RangeKeyElement' =&gt; array(&lt;br /&gt;            'AttributeName' =&gt; 'ReplyDateTime',&lt;br /&gt;            'AttributeType' =&gt; AmazonDynamoDB::TYPE_STRING&lt;br /&gt;        )&lt;br /&gt;    ),&lt;br /&gt;    'ProvisionedThroughput' =&gt; array(&lt;br /&gt;        'ReadCapacityUnits' =&gt; 10,&lt;br /&gt;        'WriteCapacityUnits' =&gt; 5&lt;br /&gt;    )&lt;br /&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Here are 3 easy steps you may need to follow if you have not already downloaded and configured Software Development kit from Amazon.&lt;br /&gt;&lt;br /&gt;# Download AWS SDK for PHP&lt;br /&gt;svn co http://svn.github.com/amazonwebservices/aws-sdk-for-php.git AWSSDKforPHP&lt;br /&gt;cd AWSSDKforPHP&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;# copy sample to config file&lt;br /&gt;mv config-sample.inc.php config.inc.php&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;# add your actual key and secret found on "security credentials" page that can be found here...&lt;br /&gt;# https://aws-portal.amazon.com/gp/aws/securityCredentials&lt;br /&gt;&lt;br /&gt;vi config.inc.php&lt;br /&gt;&lt;br /&gt;'key' =&gt; 'ABCD',&lt;br /&gt;'secret' =&gt; 'XYZ',&lt;br /&gt;'default_cache_config' =&gt; '/tmp/',&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7116412231006352940?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7116412231006352940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7116412231006352940&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7116412231006352940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7116412231006352940'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/02/nosql-support-by-aws.html' title='NoSQL support by AWS'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-920810218568582265</id><published>2012-01-05T05:12:00.000-08:00</published><updated>2012-01-05T05:14:05.426-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='redis'/><title type='text'>Hashes and sets in redis</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Hashes&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Redis's implementation of hashes makes for a perfect solution to store the object data application typically use. &lt;br /&gt;&lt;br /&gt;Let's also assume we want to store a number of fields about our users, such as a full name, email address, phone and number of visits to our application. We will use Redis's hash management commands like HSET, HGET and HINCRBY to store this information.&lt;br /&gt;&lt;br /&gt;redis&gt; hset users:jdoe name "John Doe"&lt;br /&gt;redis&gt; hset users: jdoe email "jdoe@test.com"&lt;br /&gt;redis&gt; hset users: jdoe phone "+1234567890"&lt;br /&gt;redis&gt; hincrby users:jdoe visits 1&lt;br /&gt;&lt;br /&gt;With our has built and in place, we can fetch single fields with HGET or the full hash by using the HGETALL command, for e.g.&lt;br /&gt;&lt;br /&gt;redis&gt; hget users:jdoe email&lt;br /&gt;"jdoe@test.com"&lt;br /&gt;redis&gt; hgetall users:jdoe&lt;br /&gt;1) "name"&lt;br /&gt;2) "John Doe"&lt;br /&gt;3) "email"&lt;br /&gt;4) "jdoe@test.com"&lt;br /&gt;5) "phone"&lt;br /&gt;6) "+1234567890"&lt;br /&gt;7) "visits"&lt;br /&gt;8) "1"&lt;br /&gt;&lt;br /&gt;There are other commands like HKEYS, which return the keys stored in a particular has, and HVALS, which returns only the values. Depending on how you want to retrieve your data, you may find it useful to use HGETALL or one of these to retrieve data from Redis into your application.&lt;br /&gt;&lt;br /&gt;redis&gt; hkeys users:jdoe&lt;br /&gt;1) "name"&lt;br /&gt;2) "email"&lt;br /&gt;3) "phone"&lt;br /&gt;4) "visits"&lt;br /&gt;&lt;br /&gt;redis&gt; hvals users:jdoe&lt;br /&gt;1) "John Doe"&lt;br /&gt;2) "jdoe@test.com"&lt;br /&gt;3) "+1234567890"&lt;br /&gt;4) "1"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;sets&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Sets are a natural fit for circles, because sets represent collections of data, and have native functionality to do interesting things like intersections and unions.&lt;br /&gt;&lt;br /&gt;redis&gt; sadd circle:jdoe:family users:anna&lt;br /&gt;redis&gt; sadd circle:jdoe:family users:richard&lt;br /&gt;redis&gt; sadd circle:jdoe:family users:mike&lt;br /&gt;&lt;br /&gt;redis&gt; sadd circle:jdoe:soccer users:mike&lt;br /&gt;redis&gt; sadd circle:jdoe:soccer users:adam&lt;br /&gt;redis&gt; sadd circle:jdoe:soccer users:toby&lt;br /&gt;redis&gt; sadd circle:jdoe:soccer users:apollo&lt;br /&gt;&lt;br /&gt;redis&gt; smembers circle:jdoe:family&lt;br /&gt;1) users:anna&lt;br /&gt;2) users:richard&lt;br /&gt;3) users:mike&lt;br /&gt;redis&gt; hgetall users:mike&lt;br /&gt;(...)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;redis&gt; sinter circle:jdoe:family circle:jdoe:soccer&lt;br /&gt;1) "users:mike"&lt;br /&gt;&lt;br /&gt;redis&gt; sunion circle:jdoe:family circle:jdoe:soccer&lt;br /&gt;&lt;br /&gt;1) users:anna&lt;br /&gt;2) users:richard&lt;br /&gt;3) users:mike&lt;br /&gt;4) users:adam&lt;br /&gt;5) users:toby&lt;br /&gt;6) users:apollo&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-920810218568582265?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/920810218568582265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=920810218568582265&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/920810218568582265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/920810218568582265'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/01/hashes-and-sets-in-redis.html' title='Hashes and sets in redis'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6564687001916865596</id><published>2012-01-04T01:58:00.000-08:00</published><updated>2012-01-04T02:15:17.840-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='redis'/><title type='text'>redis tips</title><content type='html'>BGSAVE can cause redis to hang upto 20 minutes and lose data. The info command will let us know the peak memory used.&lt;br /&gt;used_memory_peak_human:5.46G&lt;br /&gt;&lt;br /&gt;This shows peak usage of 5.46G. When you get close to the edge of your RAM limits, redis can start to misbehave on BGSAVE.&lt;br /&gt; &lt;br /&gt;Something else to check -- find your .rdb file and make sure it's timestamp is getting updated (ls -l) after the bgsave completes. While the bgsave&lt;br /&gt;processes, you'll see a temp rdb file next to it growing. It should grow by 10's to 100's megs a second.&lt;br /&gt;&lt;br /&gt;___&lt;br /&gt;&lt;br /&gt;You can write your own pooling layer in PHP:&lt;br /&gt;&lt;br /&gt;$connection = $pool-&gt;getConnection(...);&lt;br /&gt;...&lt;br /&gt;$pool-&gt;releaseConnection($connection);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6564687001916865596?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6564687001916865596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6564687001916865596&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6564687001916865596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6564687001916865596'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2012/01/redis-tips.html' title='redis tips'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5963887753809711678</id><published>2011-12-12T20:36:00.000-08:00</published><updated>2011-12-12T20:37:03.193-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>MySQL SSL connection</title><content type='html'>Usually ssl is installed but "disabled" by default. Here are 6 easy steps to create required files to connect using SSL&lt;br /&gt;&lt;br /&gt;mysql&gt; show variables like '%have_ssl%';&lt;br /&gt;+---------------+----------+&lt;br /&gt;| Variable_name | Value    |&lt;br /&gt;+---------------+----------+&lt;br /&gt;| have_ssl      | DISABLED |&lt;br /&gt;+---------------+----------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;# which openssl&lt;br /&gt;/usr/bin/openssl&lt;br /&gt;&lt;br /&gt;# cd /var/lib/mysql/&lt;br /&gt;# mkdir certs&lt;br /&gt;# cd certs&lt;br /&gt;# openssl genrsa 2048 &gt; ca-key.pem&lt;br /&gt;# openssl req -new -x509 -nodes -days 3600 -key ca-key.pem &gt; ca-cert.pem&lt;br /&gt;# openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem &gt; server-req.pem&lt;br /&gt;# openssl x509 -req -in server-req.pem -days 3600 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 &gt; server-cert.pem&lt;br /&gt;# openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem &gt; client-req.pem&lt;br /&gt;# openssl x509 -req -in client-req.pem -days 3600 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 &gt; client-cert.pem&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Create SSL User:&lt;br /&gt;GRANT ALL PRIVILEGES ON *.* TO 'ssluser'@'localhost' IDENTIFIED BY 'ssluser' REQUIRE SSL;&lt;br /&gt;&lt;br /&gt;# Update my.cnf and restart mysql&lt;br /&gt;[mysqld]&lt;br /&gt;ssl-ca="/var/lib/mysql/certs/ca-cert.pem"&lt;br /&gt;ssl-cert="/var/lib/mysql/certs/server-cert.pem"&lt;br /&gt;ssl-key="/var/lib/mysql/certs/server-key.pem"&lt;br /&gt;&lt;br /&gt;After restart, connect via SSL with your newly created SSL user &lt;br /&gt;mysql -ussluser -pssluser -P3430 --ssl-key=&lt;br /&gt;&lt;br /&gt;You can verify with the ‘status’ command once connected:&lt;br /&gt;mysql&gt; status&lt;br /&gt;Current user:           ssluser@localhost&lt;br /&gt;SSL:                    Cipher in use is DHE-RSA-AES256-SHA&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5963887753809711678?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5963887753809711678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5963887753809711678&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5963887753809711678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5963887753809711678'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/12/mysql-ssl-connection.html' title='MySQL SSL connection'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3811163202191307767</id><published>2011-11-10T03:37:00.000-08:00</published><updated>2011-11-23T22:48:29.192-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='usability'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='redis'/><title type='text'>redis, who?</title><content type='html'>Redis is an open source, advanced key-value store. Basically, if you can map a use case to Redis and discover you aren't at risk of running out of RAM by using Redis there is a good chance you should probably use Redis.&lt;br /&gt;&lt;br /&gt;A few examples:&lt;br /&gt;&lt;br /&gt;# You can sort by create timestamp if that is stored in epoch time.&lt;br /&gt;&lt;br /&gt;&gt; HMSET users:1 firstname 'john' lastname 'smith' created 1319729878&lt;br /&gt;"OK"&lt;br /&gt;&gt; HMSET users:2 firstname 'Jane' lastname 'Forbes' created 1319729910&lt;br /&gt;"OK"&lt;br /&gt;&gt; sadd users 1&lt;br /&gt;true&lt;br /&gt;&gt; sadd users 2&lt;br /&gt;true&lt;br /&gt;&gt; sort users get users:*-&gt;firstname by users:*-&gt;created&lt;br /&gt;["john","Jane"]&lt;br /&gt;&gt; sort users get users:*-&gt;firstname by users:*-&gt;created desc&lt;br /&gt;["Jane","john"]&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;APPLE: RED ROUND FRUIT would map to the following inserts:&lt;br /&gt;&lt;br /&gt;SADD RED:ROUND:FRUIT APPLE&lt;br /&gt;SADD :ROUND:FRUIT APPLE&lt;br /&gt;SADD RED::FRUIT APPLE&lt;br /&gt;SADD RED:ROUND: APPLE&lt;br /&gt;SADD RED:: APPLE&lt;br /&gt;SADD :ROUND: APPLE&lt;br /&gt;SADD ::FRUIT APPLE&lt;br /&gt;SADD ::: APPLE&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt; &lt;br /&gt;redis 127.0.0.1:6379&gt; SADD P1:YELLOW MANGO&lt;br /&gt;(integer) 1&lt;br /&gt;redis 127.0.0.1:6379&gt; SADD P2:TASTE MANGO&lt;br /&gt;(integer) 1&lt;br /&gt;redis 127.0.0.1:6379&gt; SADD P3:FRUIT MANGO&lt;br /&gt;(integer) 1&lt;br /&gt;redis 127.0.0.1:6379&gt; SINTER P1:YELLOW P2:TASTE&lt;br /&gt;1) "MANGO"&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;redis 127.0.0.1:6379&gt; HMSET id:4532143215432 username davejlong email dave@davejlong.com&lt;br /&gt;OK&lt;br /&gt;redis 127.0.0.1:6379&gt; HMSET user:davejlong id 4532143215432 email dave@davejlong.com&lt;br /&gt;OK&lt;br /&gt;redis 127.0.0.1:6379&gt; HGET id:4532143215432 username&lt;br /&gt;"davejlong"&lt;br /&gt;redis 127.0.0.1:6379&gt; HGET user:davejlong id&lt;br /&gt;"4532143215432"&lt;br /&gt;redis 127.0.0.1:6379&gt; HMGET user:davejlong email id&lt;br /&gt;1) "dave@davejlong.com"&lt;br /&gt;2) "4532143215432"&lt;br /&gt;redis 127.0.0.1:6379&gt; DEL user:davejlong&lt;br /&gt;(integer) 1&lt;br /&gt;redis 127.0.0.1:6379&gt; DEL id:4532143215432&lt;br /&gt;(integer) 1&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Redis can be easily used in shell script or at command prompt.&lt;br /&gt;It will be extremely useful for storing the standard out data of other commands. &lt;br /&gt;&lt;br /&gt;[root@server]# echo -n "testing" | /pat/to/redis/src/redis-cli -x set my_pass &gt; /dev/null 2&gt;&amp;1&lt;br /&gt;[root@server]# echo $?&lt;br /&gt;0&lt;br /&gt; &lt;br /&gt;[root@server]# /pat/to/redis/src/redis-cli --raw get my_pass&lt;br /&gt;testing&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;We can write a shell script to import the data from mysql or use a tool like "awk"&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;mysql pdb_name -Bse"select comments, concat(fee, status) as myfee from company limit 100000;" | while read -r account myfee&lt;br /&gt;do&lt;br /&gt;echo -n $myfee | /home/redis-2.2.12/src/redis-cli -h 10.10.10.100 -p 6379 -x set $account &gt; /dev/null 2&gt;&amp;1&lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;mysql pdb_name -Bse"select comments, concat(fee, status) as myfee from company limit 100000;" | awk "{print \"set \" \$1 \" \" \$2}" | /home/redis-2.2.12/src/redis-cli -h 10.10.10.100 -p 6379 &gt; /dev/null 2&gt;&amp;1&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;redis&gt; select 3&lt;br /&gt;All subsequent commands will then use database 3, until you issue another SELECT&lt;br /&gt;&lt;br /&gt;redis&gt; flushdb&lt;br /&gt;drop all the data in a single database&lt;br /&gt;&lt;br /&gt;redis&gt; FLUSHALL&lt;br /&gt;drop all the data in all databases&lt;br /&gt;&lt;br /&gt;in redis.conf — by default, it is set to 16. Simply set it to a higher number if you need more:&lt;br /&gt;databases 42&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3811163202191307767?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3811163202191307767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3811163202191307767&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3811163202191307767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3811163202191307767'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/11/redis-who.html' title='redis, who?'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1280964119468797742</id><published>2011-10-28T02:13:00.000-07:00</published><updated>2011-11-09T21:27:00.933-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='usability'/><category scheme='http://www.blogger.com/atom/ns#' term='splunk'/><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Using Splunk with forwarding</title><content type='html'>Splunk is a log, monitoring and reporting tool for IT system administrators with search capabilities.  It crawls logs, metrics, and other data from applications, servers and network devices and indexes it in a searchable repository from which it can generate graphs, SQL reports and alerts.&lt;br /&gt;&lt;br /&gt;#### Setup splunk as a Reciever #####&lt;br /&gt;&lt;br /&gt;Install splunk:&lt;br /&gt;splunk-4.2.4-110225-linux-2.6-x86_64.rpm (26M) &lt;br /&gt;&lt;br /&gt;start splunk:&lt;br /&gt;# /opt/splunk/bin/splunk start&lt;br /&gt;&lt;br /&gt;Splunk web UI is here...&lt;br /&gt;http://localhost:8000&lt;br /&gt;&lt;br /&gt;1. Login to WebUI using the above mentioned credentionals. eg. http://10.10.10.35:8000&lt;br /&gt;2. Go to Manager » Forwarding and receiving » Receive data&lt;br /&gt;3. Click on New Button and add default port i.e. 9997&lt;br /&gt;4. Click on save button to save the settings.&lt;br /&gt;Note: If you are running any firewall please allow the above Port.&lt;br /&gt;&lt;br /&gt;####### Setup Splunk as a Forwarder ####&lt;br /&gt;Install forwarder in addition to splunk as mentioned above:&lt;br /&gt;splunkforwarder-4.2.4-110225-linux-2.6-x86_64.rpm (13M) &lt;br /&gt;&lt;br /&gt;#   /opt/splunk/bin/splunk start&lt;br /&gt;# ./splunk enable app SplunkLightForwarder -auth &lt;br /&gt;Splunk username: admin&lt;br /&gt;Password: changeme&lt;br /&gt;&lt;br /&gt;# ./splunk add forward-server 10.10.10.35:9997 -auth admin&lt;br /&gt;# ./splunk restart&lt;br /&gt;# ./splunk add monitor /etc/hosts&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Splunk can also be used to search within data.&lt;br /&gt;&lt;br /&gt;time mysqldump -h10.10.10.10 -uroot -proot@123 -P3311 -f --databases db1 db2 db3 db4 --skip-extended-insert --skip-lock-tables --ignore-table=db1.balance_extra --ignore-table=db1.fee_log --ignore-table=db1.transaction  &gt; search_selected_data.txt&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;It is recommended to create a new index at the time of adding a file to splunk. The index file can be removed using the following syntax.&lt;br /&gt;&lt;br /&gt;// Remove the source from future searches events &lt;br /&gt;source='search_selected_data.txt' | delete&lt;br /&gt;&lt;br /&gt;// delete indexed data&lt;br /&gt;source='search_selected_data.txt' | clean&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;// Splunk will not merge lines into combined events.&lt;br /&gt;set SHOULD_LINEMERGE to "false" in props.conf &lt;br /&gt;&lt;br /&gt;The above setting will affect all searches. To apply the new setting to a single source,&lt;br /&gt;&lt;br /&gt;[source:///path/to/file]&lt;br /&gt;SHOULD_LINEMERGE = false&lt;br /&gt;&lt;br /&gt;or to do it on a sourcetype level,&lt;br /&gt;&lt;br /&gt;[your_sourcetype]&lt;br /&gt;SHOULD_LINEMERGE = false&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1280964119468797742?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1280964119468797742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1280964119468797742&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1280964119468797742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1280964119468797742'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/10/using-splunk-with-forwarding.html' title='Using Splunk with forwarding'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8296852431096577595</id><published>2011-09-23T05:11:00.001-07:00</published><updated>2011-09-23T05:20:26.069-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Object oriented Python</title><content type='html'>Main advantage of using python is that it is a truly Object oriented scripting language.&lt;br /&gt;&lt;br /&gt;outfile = open('/home/shantanu/test.txt', 'w')&lt;br /&gt;outfile.write('this is test')&lt;br /&gt;&lt;br /&gt;The above will not explicitly close the file. Following are the 2 ways to close the file once it is not required anymore.&lt;br /&gt;&lt;br /&gt;outfile = open('/home/shantanu/test.txt', 'w')&lt;br /&gt;try:&lt;br /&gt;outfile.write('this is test')&lt;br /&gt;finally:&lt;br /&gt;outilfe.close()&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;with open(r'/home/shantanu/test1.txt', 'w') as myfile:&lt;br /&gt;outfile.write('this is test1')&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Compare it with PHP and you will see what I mean. PHP seems to be more like variables and function prone language.&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$fh = fopen("testfile.txt", 'w');&lt;br /&gt;fwrite($fh, "adding one line");&lt;br /&gt;fclose($fh);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Finally nothing can beat shell, since it is so robust, logical and have direct approach like this...&lt;br /&gt;&lt;br /&gt;echo "shell is the king" &gt; /home/shantanu/testfile.txt&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8296852431096577595?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8296852431096577595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8296852431096577595&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8296852431096577595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8296852431096577595'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/09/object-oriented-python.html' title='Object oriented Python'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-667528138976766764</id><published>2011-09-23T03:16:00.000-07:00</published><updated>2011-09-23T03:17:41.739-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Using performance schema to know the query locks</title><content type='html'>The following line should be added to my.cnf to enable performance schema.&lt;br /&gt;performance-schema&lt;br /&gt;&lt;br /&gt;It is not enabled by default because it has some performance over-heads. You can now run the following queries to find the thread ID's those are having issues with mysql query locks.&lt;br /&gt;&lt;br /&gt;select THREAD_ID, EVENT_ID, EVENT_NAME, SOURCE, TIMER_START, OBJECT_INSTANCE_BEGIN, OPERATION &lt;br /&gt;FROM performance_schema.events_waits_current &lt;br /&gt;WHERE THREAD_ID  in(select LOCKED_BY_THREAD_ID FROM performance_schema.mutex_instances where LOCKED_BY_THREAD_ID is not null);&lt;br /&gt;&lt;br /&gt;select * from performance_schema.threads;&lt;br /&gt;&lt;br /&gt;select * from performance_schema.mutex_instances where LOCKED_BY_THREAD_ID is not null;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-667528138976766764?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/667528138976766764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=667528138976766764&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/667528138976766764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/667528138976766764'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/09/using-performance-schema-to-know-query.html' title='Using performance schema to know the query locks'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-761002587340555546</id><published>2011-08-29T05:07:00.001-07:00</published><updated>2011-08-29T05:07:26.027-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Script to search locked threads</title><content type='html'>The following script will pick up the thread-id from innodb status page and select the last queries executed by that thread.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;mysql -e"show engine innodb status\G" | grep "MySQL thread id " | awk -F"," '{print $1}' | replace 'MySQL thread id' '' | tail | while read -r connectid&lt;br /&gt;do&lt;br /&gt;tail -1000000 /var/log/mysql/general.log | awk '$1 == "'$connectid'" || $3 == "'$connectid'" { print $0 }' | head&lt;br /&gt;tail -1000000 /var/log/mysql/general.log | awk '$1 == "'$connectid'" || $3 == "'$connectid'" { print $0 }' | tail&lt;br /&gt;done&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-761002587340555546?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/761002587340555546/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=761002587340555546&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/761002587340555546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/761002587340555546'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/08/script-to-search-locked-threads.html' title='Script to search locked threads'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7644038560697790994</id><published>2011-08-15T23:57:00.000-07:00</published><updated>2011-09-11T21:39:50.351-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Analysing general query log</title><content type='html'>Here are a few commands to know the schema, IP accessing the data using general log.&lt;br /&gt;&lt;br /&gt;time grep -w Connect /var/log/mysql/general.log | awk -F'Connect' '{print $2}' &gt; connectme.log&lt;br /&gt;&lt;br /&gt;// connection string&lt;br /&gt;sort connectme.log | uniq -c | sort -n&lt;br /&gt;   3350      application_user@10.10.11.26 on db1_16JUL2011&lt;br /&gt;   7330      application_user@172.16.55.133 on FWQAdb2&lt;br /&gt;   7716      application_user@10.10.11.14 on FWQAdb3&lt;br /&gt;  10084      application_user@172.16.155.133 on FWQAdb4&lt;br /&gt;&lt;br /&gt;// schema, user and IP count&lt;br /&gt;awk -F' on' '{print $2}' connectme.log | sort | uniq -c | sort -n&lt;br /&gt;   4528  db1_29062011&lt;br /&gt;   5027  db2_16JUL2011&lt;br /&gt;   9295  FWQAdb3&lt;br /&gt;  10084  FWQAdb4&lt;br /&gt;  10488  FWQAdb5&lt;br /&gt;&lt;br /&gt;awk -F'@' '{print $1}' connectme.log | sort | uniq -c | sort -n&lt;br /&gt;     46      amar&lt;br /&gt;  28450      akbar&lt;br /&gt;  31453      anthony&lt;br /&gt;  41646      dbagroup&lt;br /&gt;&lt;br /&gt;awk -F'@' '{print $2}' connectme.log | awk '{print $1}' | sort | uniq -c | sort -n&lt;br /&gt;   4189 10.10.11.167&lt;br /&gt;   7157 10.10.11.26&lt;br /&gt;   8600 10.10.10.67&lt;br /&gt;   9073 10.10.11.14&lt;br /&gt;  17414 172.16.155.133&lt;br /&gt;&lt;br /&gt;// failed connections analysis&lt;br /&gt;grep 'Access denied' connectme.log | awk -F'@' '{print $1}' | awk '{print $NF}' | sort | uniq -c | sort -n&lt;br /&gt;      1 'amar'&lt;br /&gt;      1 'akbar'&lt;br /&gt;     13 'anthony'&lt;br /&gt;     16 'user1'&lt;br /&gt;    831 'user2'&lt;br /&gt;&lt;br /&gt;grep 'Access denied' connectme.log | awk -F'@' '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n&lt;br /&gt;      6 '10.10.10.69'&lt;br /&gt;     26 '10.10.11.140'&lt;br /&gt;    815 '10.10.11.57'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7644038560697790994?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7644038560697790994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7644038560697790994&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7644038560697790994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7644038560697790994'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/08/analysing-general-query-log.html' title='Analysing general query log'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7047250545480039522</id><published>2011-08-12T00:48:00.000-07:00</published><updated>2011-08-12T00:49:19.840-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>new data-directory for MySQL</title><content type='html'>Sometimes you need fresh mysql installation. You need to run script to create default mysql database and system tables. The script is called "mysql_install_db" and is either in the bin or in scripts directory of your mysql installation. Change the my.cnf to reflect new datadir and run mysql_install_db for it to create mysql database and system tables in the new datatir and then start mysqld_safe.&lt;br /&gt;&lt;br /&gt;/usr/bin/mysql_install_db --datadir=/mnt/mysql3310&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7047250545480039522?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7047250545480039522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7047250545480039522&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7047250545480039522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7047250545480039522'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/08/new-data-directory-for-mysql.html' title='new data-directory for MySQL'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5687625414179641361</id><published>2011-08-07T00:48:00.000-07:00</published><updated>2011-08-07T00:49:31.281-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Resetting root password</title><content type='html'>If you have forgotten your root password, you will need to start mysql service with --skip-grant-tables mode and then run the following 2 commands to reset it to root / root@123&lt;br /&gt;&lt;br /&gt;UPDATE mysql.user SET Password = password('root@123') WHERE Host = 'localhost' AND User = 'root';&lt;br /&gt;&lt;br /&gt;REPLACE INTO mysql.user VALUES ('%','root','*A00C34073A26B40AB4307650BFB9309D6BFA6999', 'Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y','Y','Y','Y','Y', 'Y','Y','Y','Y','Y','','','','', 0,0,0,0,'','');&lt;br /&gt;&lt;br /&gt;You may now remove the skip grant tables option and restart mysql service. I assume you are not using old-passwords option in my.cnf that makes it compatible with mysql version 3.0!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5687625414179641361?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5687625414179641361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5687625414179641361&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5687625414179641361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5687625414179641361'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/08/resetting-root-password.html' title='Resetting root password'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4022872376008870405</id><published>2011-08-06T21:33:00.000-07:00</published><updated>2011-08-06T21:34:23.622-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Changing all users and passwords</title><content type='html'>Hi,&lt;br /&gt;When the data is made available for development, the DBA needs to change the user privileges to make it more restrictive.&lt;br /&gt;The following statement will create all current users with localhost and % hosts and have the same password for all these users.&lt;br /&gt;&lt;br /&gt;mysql -hIP_ADDRESS -uroot -pold_password -P3311 -Bse"&lt;br /&gt;select concat(\"grant all on *.* to '\",User,\"'@'%' identified by 'new_password' with grant option;\") from mysql.user group by user&lt;br /&gt;UNION&lt;br /&gt;select concat(\"grant all on *.* to '\",User,\"'@'localhost' identified by 'new_password' with grant option;\") from mysql.user group by user;" | mysql -h10.10.10.24 -uroot -pold_password -P3311&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4022872376008870405?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4022872376008870405/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4022872376008870405&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4022872376008870405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4022872376008870405'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/08/changing-all-users-and-passwords.html' title='Changing all users and passwords'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2487513381053681620</id><published>2011-08-03T23:07:00.000-07:00</published><updated>2011-08-03T23:08:08.296-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>socket file location</title><content type='html'>There are times when you need to supply the IP address even if you are accessing mysql from localhost. This may happen due to changed socket file.&lt;br /&gt;&lt;br /&gt;If I do not change the default location of socket file, I can access mysql from localhost with or without IP&lt;br /&gt;socket=/var/lib/mysql/mysql.sock&lt;br /&gt;&lt;br /&gt;But If I change the socket location to some other path in my [mysqld] section then I need to add it to [mysql] and [client] section.&lt;br /&gt;&lt;br /&gt;[mysql]&lt;br /&gt;socket=/mysqldata1/mysql/mysql.sock&lt;br /&gt;&lt;br /&gt;[client]&lt;br /&gt;socket=/mysqldata1/mysql/mysql.sock&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2487513381053681620?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2487513381053681620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2487513381053681620&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2487513381053681620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2487513381053681620'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/08/socket-file-location.html' title='socket file location'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8948447578108536585</id><published>2011-07-25T23:23:00.002-07:00</published><updated>2011-08-08T02:38:41.497-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Finding errors in the .sql script</title><content type='html'>You can disable foreign key and run the script to check if mysql throws any errors other than foreign key constraint.&lt;br /&gt;&lt;br /&gt;# cat foreign_key.txt &lt;br /&gt;set foreign_key_checks=0;&lt;br /&gt;&lt;br /&gt;# cat foreign_key.txt db_name_updates.sql | mysql db_name&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;When you need to import data, it is better to disable foreign key checks temporarily so that queries do not fail.&lt;br /&gt;mysql&gt; SET foreign_key_checks = 0&lt;br /&gt;&lt;br /&gt;The problem with this is that you have to insert the statement at the beginning of every import file. If mysql reconnects automatically, it "forgets" the setting. There is no way to disable it at server level.&lt;br /&gt;&lt;br /&gt;mysql&gt; SET GLOBAL init_connect='SET foreign_key_checks = 0';&lt;br /&gt;&lt;br /&gt;We can use initial connect feature to disable foregin keys. Any user that does not have "super" privilege will follow this command.&lt;br /&gt;If you are creating users with "grant all on *.* " syntax, then you are out of luck. &lt;br /&gt;I would suggest that a new user can be created for the purpose of executing the scripts those needs to bypass the foreign key checks. The easiest way to create such user is given below:&lt;br /&gt;&lt;br /&gt;grant all on *.* to 'reader'@'%' identified by 'reader@123' with grant option;&lt;br /&gt;revoke super on *.* from 'reader'@'%';&lt;br /&gt;&lt;br /&gt;You can now use the "reader" user to execute the scripts those needs to by executed at any cost and should bypass foreign-keys.&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;In order to know the exact queries where mysql found an error, use the following syntax.&lt;br /&gt;# cat  db_name_updates.sql | mysql db_name -f -vvv &gt; db_name_updates_success.txt 2&gt; db_name_updates_err.txt&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8948447578108536585?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8948447578108536585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8948447578108536585&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8948447578108536585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8948447578108536585'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/07/finding-errors-in-sql-script_25.html' title='Finding errors in the .sql script'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5530054849099189519</id><published>2011-07-25T02:03:00.000-07:00</published><updated>2011-07-25T02:04:13.165-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Managing Auto-incremented ID</title><content type='html'>Managing the auto_ids can be very difficult while automating the mysql process. &lt;br /&gt;Here is a way to handle it more efficiently.&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into country values (NULL, 'Norway');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;The following statement will save the last auto id to a variable as well as write it to a text file.&lt;br /&gt;&lt;br /&gt;mysql&gt; select @myvar:=last_insert_id() into outfile 'country_last_id.txt';&lt;br /&gt;&lt;br /&gt;# cat /var/lib/mysql/test/country_last_id.txt&lt;br /&gt;5&lt;br /&gt;&lt;br /&gt;Any script can now pick up this auto_incremented value from the text file and use it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5530054849099189519?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5530054849099189519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5530054849099189519&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5530054849099189519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5530054849099189519'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/07/managing-auto-incremented-id.html' title='Managing Auto-incremented ID'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-542440232312202606</id><published>2011-07-23T21:42:00.000-07:00</published><updated>2011-07-23T21:49:34.269-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql FAQ'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>schema and data sync</title><content type='html'>We are going to learn how update the production data to be in sync with the development server. We will use 3 utilities.&lt;br /&gt;&lt;br /&gt;1) diff : This is linux built-in command to compare 2 files.&lt;br /&gt;&lt;br /&gt;2) Maatkit: This will be used to compare checksum values of 2 tables and the data differences.&lt;br /&gt;&lt;a href="http://www.maatkit.org/doc/"&gt;http://www.maatkit.org/doc/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;3) schemasync: This utility is used to compare structural differences.&lt;br /&gt;&lt;a href="http://schemasync.org/"&gt;http://schemasync.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;______________________________________&lt;br /&gt;&lt;br /&gt;I) Schema sync&lt;br /&gt;&lt;br /&gt;We will first make sure that the table structure of localhost mktest table matches with the SERVER_A table structure.&lt;br /&gt;In the following example, the column "mytime" is missing. How do we know that? How do we create the alter table statement?&lt;br /&gt;&lt;br /&gt;server:localhost&lt;br /&gt;schema: test&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mktest;&lt;br /&gt;+----+----------+--------+------+&lt;br /&gt;| id | f_amount | myname | city |&lt;br /&gt;+----+----------+--------+------+&lt;br /&gt;|  1 |     NULL | abc    | NULL | &lt;br /&gt;|  3 |     NULL | abc    | NULL | &lt;br /&gt;|  6 |     NULL | abc    | NULL | &lt;br /&gt;|  8 |     NULL | abc    | NULL | &lt;br /&gt;|  9 |     NULL | abc    | NULL | &lt;br /&gt;| 21 |     NULL | abc    | NULL | &lt;br /&gt;+----+----------+--------+------+&lt;br /&gt;6 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;server: SERVER_A&lt;br /&gt;schema: test&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mktest;&lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;| id | f_amount | myname | city | mytime |&lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;|  1 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  3 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  5 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  6 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  8 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  9 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;| 11 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;7 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# diff &lt;(mysqldump -hSERVER_A -uroot -proot@123 test mktest --skip-extended-insert -d -R) &lt;(mysqldump -hlocalhost -uroot -proot@123 test mktest --skip-extended-insert -d -R) --side-by-side --suppress-common-lines --width=190 | more&lt;br /&gt;-- Host: SERVER_A    Database: test  | -- Host: localhost    Database: test&lt;br /&gt;  `mytime` datetime default NULL, &lt;&lt;br /&gt;) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1; | ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1;&lt;br /&gt;&lt;br /&gt;*** mytime column needs to be added and the table type needs to be changed from InnoDB to MyISAM ***&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;The diff utility does not generate ready to execute alter statements. We need a third party utility called schemasync.&lt;br /&gt;&lt;br /&gt;# schemasync mysql://root:root@123@localhost:3306/test mysql://root:root@123@SERVER_A:3306/test&lt;br /&gt;&lt;br /&gt;# cat /home/shantanu/test.20110720.patch.sql&lt;br /&gt;USE `test`;&lt;br /&gt;ALTER TABLE `mktest` ADD COLUMN `mytime` datetime NULL AFTER `city`;&lt;br /&gt;&lt;br /&gt;It will also generate an alter table statement to change the table type.&lt;br /&gt;&lt;br /&gt;______________________________________&lt;br /&gt;&lt;br /&gt;II) Data Sync:&lt;br /&gt;&lt;br /&gt;Now that our structure is in order, let's see what records are added / updated.&lt;br /&gt;&lt;br /&gt;server:localhost&lt;br /&gt;schema: test&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mktest;&lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;| id | f_amount | myname | city | mytime |&lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;|  1 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  3 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  6 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  8 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  9 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;| 21 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;6 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;server: SERVER_A&lt;br /&gt;schema: test&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mktest;&lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;| id | f_amount | myname | city | mytime |&lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;|  1 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  3 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  5 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  6 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  8 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;|  9 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;| 11 |     NULL | abc    | NULL | NULL   | &lt;br /&gt;+----+----------+--------+------+--------+&lt;br /&gt;7 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;a) Checksum match: &lt;br /&gt;We need to find out if the checksum values of these 2 tables match. If the row count and checksum values are the same, the table are exactly the same.&lt;br /&gt;&lt;br /&gt;# /usr/bin/mk-table-checksum h=SERVER_A,u=root,p=root@123,P=3306 --databases test  --tables mktest h=localhost,u=root,p=root@123,P=3306 --databases test --tables mktest --count | /usr/bin/mk-checksum-filter&lt;br /&gt;test     mktest     0 SERVER_A        MyISAM          7         4d38da45    0    0 NULL NULL&lt;br /&gt;test     mktest     0 localhost       MyISAM          6         f1e08b3d    0    0 NULL NULL&lt;br /&gt;&lt;br /&gt;There is a difference of 1 row and the checksum value does not match. So we need to find out what are those records.&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;b) Finding differences:&lt;br /&gt;&lt;br /&gt;# diff &lt;(mysqldump -hSERVER_A -uroot -proot@123 test mktest --skip-extended-insert) &lt;(mysqldump -hlocalhost -uroot -proot@123 test mktest --skip-extended-insert) --side-by-side --suppress-common-lines --width=190 | more &lt;br /&gt;-- Host: SERVER_A    Database: test | -- Host: localhost    Database: test&lt;br /&gt;) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;  | ) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=latin1;&lt;br /&gt;INSERT INTO `mktest` VALUES (5,NULL,'abc',NULL,NULL);   &lt;&lt;br /&gt;INSERT INTO `mktest` VALUES (11,NULL,'abc',NULL,NULL);  | INSERT INTO `mktest` VALUES (21,NULL,'abc',NULL,NULL);&lt;br /&gt;&lt;br /&gt;The above screen shows that one row is missing from localhost while the another row ID should be 11 instead of 21.&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;c) Generate SQL:&lt;br /&gt;So we need one insert statement and one update. The maatkit table sync utility has generated delete / insert combo instead of update as shown below:&lt;br /&gt;&lt;br /&gt;# /usr/bin/mk-table-sync --print h=SERVER_A,u=root,p=root@123,P=3306 --databases test  --tables mktest h=localhost,u=root,p=root@123,P=3306 --databases test --tables mktest&lt;br /&gt;DELETE FROM `test`.`mktest` WHERE `id`='21' LIMIT 1 ;&lt;br /&gt;INSERT INTO `test`.`mktest`(`id`, `f_amount`, `myname`, `city`, `mytime`) VALUES ('5', NULL, 'abc', NULL, NULL) ;&lt;br /&gt;INSERT INTO `test`.`mktest`(`id`, `f_amount`, `myname`, `city`, `mytime`) VALUES ('11', NULL, 'abc', NULL, NULL) ;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-542440232312202606?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/542440232312202606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=542440232312202606&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/542440232312202606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/542440232312202606'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/07/schema-and-data-sync.html' title='schema and data sync'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2465471317542329098</id><published>2011-07-14T23:45:00.000-07:00</published><updated>2011-07-14T23:46:33.472-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><title type='text'>Remove all except latest 2 files</title><content type='html'>Let's assume I want to remove all the older backup files from the current directory, except the last 2 latest files. One way of doing this is to move the latest file to another location and then remove all the files starting with data_diff_*&lt;br /&gt;&lt;br /&gt;But such a process can not be set in cron nor it can be used in a script.&lt;br /&gt;Here is a linux command that will do this for you. For free!!&lt;br /&gt;&lt;br /&gt;# ls -lht&lt;br /&gt;total 169M&lt;br /&gt;-rw-r--r-- 1 root  root  1.8M Apr 25 00:55 data_diff_0425.txt.zip&lt;br /&gt;-rw-r--r-- 1 mysql mysql 1.8M Apr 24 00:55 data_diff_0424.txt.zip&lt;br /&gt;-rw-r--r-- 1 mysql mysql 1.8M Apr 23 00:55 data_diff_0423.txt.zip&lt;br /&gt;-rw-r--r-- 1 mysql mysql 1.8M Apr 22 00:55 data_diff_0422.txt.zip&lt;br /&gt;-rw-r--r-- 1 mysql mysql 3.5M Apr 21 00:55 data_diff_0421.txt.zip&lt;br /&gt;-rw-r--r-- 1 mysql mysql 1.8M Apr 20 00:55 data_diff_0420.txt.zip&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;#  (ls data_diff_*.txt.zip -t | head -n 2; ls data_diff_*.txt.zip)| sort | uniq -u | xargs rm&lt;br /&gt;&lt;br /&gt;# ls -lht&lt;br /&gt;total 3.5M&lt;br /&gt;-rw-r--r-- 1 root  root  1.8M Apr 25 00:55 data_diff_0425.txt.zip&lt;br /&gt;-rw-r--r-- 1 mysql mysql 1.8M Apr 24 00:55 data_diff_0424.txt.zip&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2465471317542329098?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2465471317542329098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2465471317542329098&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2465471317542329098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2465471317542329098'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/07/remove-all-except-latest-2-files.html' title='Remove all except latest 2 files'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1221872035162354472</id><published>2011-06-22T04:10:00.000-07:00</published><updated>2011-08-13T03:24:39.971-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Triggers management</title><content type='html'>List of all triggers:&lt;br /&gt;SELECT TRIGGER_SCHEMA AS Database_Name, EVENT_OBJECT_TABLE AS Table_Name,&lt;br /&gt;REPLACE(group_concat(IF(EVENT_MANIPULATION = 'UPDATE' AND ACTION_TIMING='BEFORE', TRIGGER_NAME, '')), ',', '') AS BEFORE_UPDATE,&lt;br /&gt;REPLACE(group_concat(IF(EVENT_MANIPULATION = 'UPDATE' AND ACTION_TIMING = 'AFTER', TRIGGER_NAME, '')), ',', '')  AS AFTER_UPDATE,&lt;br /&gt;REPLACE(group_concat(IF(EVENT_MANIPULATION = 'INSERT' AND ACTION_TIMING='BEFORE', TRIGGER_NAME, '')), ',', '')  AS BEFORE_INSERT,&lt;br /&gt;REPLACE(group_concat(IF(EVENT_MANIPULATION = 'INSERT' AND ACTION_TIMING = 'AFTER', TRIGGER_NAME, '')), ',', '')  AS AFTER_INSERT,&lt;br /&gt;REPLACE(group_concat(IF(EVENT_MANIPULATION = 'DELETE' AND ACTION_TIMING='BEFORE', TRIGGER_NAME, '')), ',', '')  AS BEFORE_DELETE,&lt;br /&gt;REPLACE(group_concat(IF(EVENT_MANIPULATION = 'DELETE' AND ACTION_TIMING = 'AFTER', TRIGGER_NAME, '')), ',', '')  AS AFTER_DELETE&lt;br /&gt;from information_schema.triggers GROUP BY TRIGGER_SCHEMA, EVENT_OBJECT_TABLE ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Remove all triggers:&lt;br /&gt;select concat('drop trigger if exists `',trigger_schema,'`.`',trigger_name,'`;') cmd from information_schema.triggers&lt;br /&gt;where trigger_schema='test';&lt;br /&gt;&lt;br /&gt;Disable all AFTER triggers:&lt;br /&gt;mysql -uroot -proot@123 -Bse"SELECT IF(ACTION_TIMING = 'AFTER', CONCAT('mv /var/lib/mysql/', TRIGGER_SCHEMA, '/', EVENT_OBJECT_TABLE, '.TRG', ' ', ' /var/lib/mysql/', TRIGGER_SCHEMA, '/', EVENT_OBJECT_TABLE, '.TRG.bak' ), '') AS Backup from information_schema.triggers GROUP BY TRIGGER_SCHEMA, EVENT_OBJECT_TABLE " | sh&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Disable all triggers:&lt;br /&gt;find `grep datadir /etc/my.cnf | awk -F'=' '{print $2}'` -name "*.TRG" | xargs -i mv {} {}.bak&lt;br /&gt;&lt;br /&gt;Enable all Triggers:&lt;br /&gt;find `grep datadir /etc/my.cnf | awk -F'=' '{print $2}'` -name "*.TRG.bak" | xargs -i rename '.bak' '' {}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// following trigger will dump each trigger from selected dbName into a separate file.&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;dbName=${1:-'default_db'}&lt;br /&gt;host='10.10.10.10'&lt;br /&gt;user='root'&lt;br /&gt;password='root@123'&lt;br /&gt;port='3311'&lt;br /&gt;mysql -u$user -p$password -h$host -P$port -Bse"SELECT TRIGGER_NAME FROM information_schema.triggers WHERE TRIGGER_SCHEMA = '$dbName' ;" | while read -r trigName&lt;br /&gt;&lt;br /&gt;do&lt;br /&gt;echo $trigName&lt;br /&gt;mysql  -u$user -p$password -h$host -P$port -Bse"select sql_code from mysql.SHOW_CREATE_TRIGGERS where TRIGGER_SCHEMA='$dbName' AND trigger_name = \"$trigName\"\G" &gt; $trigName.sql&lt;br /&gt;done&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1221872035162354472?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1221872035162354472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1221872035162354472&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1221872035162354472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1221872035162354472'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/06/triggers-management.html' title='Triggers management'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4337883117027851868</id><published>2011-06-06T03:05:00.000-07:00</published><updated>2011-06-06T03:06:23.143-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>definers in triggers and procedures</title><content type='html'>The stored procedures and triggers have the "definer" clause that keeps the non-privileged users from accessing these objects. But most often it is a problem since the trigger won't work unless the user is present. The update/ insert statements will fail if the respective triggers can not be activated. The only way is to find and create required users.&lt;br /&gt;&lt;br /&gt;mysql&gt; select DEFINER from  information_schema.TRIGGERS AS a &lt;br /&gt;LEFT JOIN mysql.user AS b ON a.DEFINER = CONCAT(User, '@', Host) WHERE CONCAT(uSER, '@', Host) IS NULL group by a.DEFINER;&lt;br /&gt;+---------------------+&lt;br /&gt;| DEFINER             |&lt;br /&gt;+---------------------+&lt;br /&gt;| ABC@199.168.101.% | &lt;br /&gt;+---------------------+&lt;br /&gt;1 row in set (1.41 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select DEFINER from information_schema.ROUTINES AS a &lt;br /&gt;LEFT JOIN mysql.user AS b ON a.DEFINER = CONCAT(User, '@', Host) WHERE CONCAT(uSER, '@', Host) IS NULL group by a.DEFINER;&lt;br /&gt;+-----------------------+&lt;br /&gt;| DEFINER               |&lt;br /&gt;+-----------------------+&lt;br /&gt;| MNP@199.168.100.% | &lt;br /&gt;| companycuser@     | &lt;br /&gt;+-----------------------+&lt;br /&gt;2 rows in set (0.02 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4337883117027851868?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4337883117027851868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4337883117027851868&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4337883117027851868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4337883117027851868'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/06/definers-in-triggers-and-procedures.html' title='definers in triggers and procedures'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8046110114643866204</id><published>2011-05-26T04:30:00.000-07:00</published><updated>2011-05-26T04:31:47.577-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><title type='text'>Check slave data</title><content type='html'>We need to check if the slave is in sync with the master data. Let's assume the slave IP is 10.10.10.3&lt;br /&gt;Now assuming that the localhost is the master server, I can simply run the slave_check.sh script to check the data discrepancy.&lt;br /&gt;&lt;br /&gt;# cat slave_check.sh &lt;br /&gt;#/bin/sh&lt;br /&gt;myslave=${1:-10.10.10.3}&lt;br /&gt;for dbName in `mysqlshow`&lt;br /&gt;do&lt;br /&gt;mk-table-checksum h=localhost,u=root,p=root@123,P=3306 --databases $dbName h=$myslave,u=root,p=root@123,P=3306 --databases $dbName --no-crc --count | mk-checksum-filter&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8046110114643866204?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8046110114643866204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8046110114643866204&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8046110114643866204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8046110114643866204'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/check-slave-data.html' title='Check slave data'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4156478796718091816</id><published>2011-05-26T02:28:00.001-07:00</published><updated>2011-05-26T02:28:43.465-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>hierarchy in parameters</title><content type='html'>While connecting to mysql, the sequence of options does matter. For e.g. the following does not work...&lt;br /&gt;mysql -uUser -pPassWd --socket=/tmp/mysql.sock2 &lt;br /&gt;&lt;br /&gt;But this works as expected.&lt;br /&gt;mysql --socket=/tmp/mysql.sock2 -uUser -PPassWd&lt;br /&gt;&lt;br /&gt;The following does not work either...&lt;br /&gt;mysql --socket=/tmp/mysql.sock2 -uUser -pPassWd --no-defaults&lt;br /&gt;&lt;br /&gt;But the following should work:&lt;br /&gt;mysql --no-defaults --socket=/tmp/mysql.sock2 -uUser -pPassWd &lt;br /&gt;&lt;br /&gt;Interesting!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4156478796718091816?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4156478796718091816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4156478796718091816&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4156478796718091816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4156478796718091816'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/hierarchy-in-parameters.html' title='hierarchy in parameters'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1803377495603815987</id><published>2011-05-25T01:41:00.001-07:00</published><updated>2011-05-25T01:41:52.838-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><title type='text'>NFS mounting to share free disk space</title><content type='html'>If is very easy to mount a drive from one server to the other on the same network. NFS sharing will come handy when we have a lot of disk space on server 1 and very less space on 2. Once mounted, the files in that directory can be easily shared between the two (or more) servers.&lt;br /&gt;&lt;br /&gt;1) Check if portmap and nfs services are running on both servers. start service if necessary.&lt;br /&gt;&lt;br /&gt;# /sbin/service portmap status&lt;br /&gt;portmap (pid 2557) is running...&lt;br /&gt;&lt;br /&gt;# /sbin/service nfs status&lt;br /&gt;rpc.mountd (pid 2376) is running...&lt;br /&gt;nfsd (pid 2373 2372 2371 2370 2369 2368 2367 2366) is running...&lt;br /&gt;rpc.rquotad (pid 2344) is running...&lt;br /&gt;&lt;br /&gt;2) On the server (10.10.10.1) where enough disk is available...&lt;br /&gt;i) create directory to share:&lt;br /&gt;# mkdir /db-nfs&lt;br /&gt;&lt;br /&gt;ii) Add entry to exports file:&lt;br /&gt;# cat /etc/exports &lt;br /&gt;/db-nfs   10.10.10.0/24(rw,sync,no_root_squash)&lt;br /&gt;&lt;br /&gt;iii) activate sharing:&lt;br /&gt;# /usr/sbin/exportfs -a&lt;br /&gt;&lt;br /&gt;3) On the server (10.10.10.2) where we need more disk space...&lt;br /&gt;i) Mount the drive&lt;br /&gt;&lt;br /&gt;/bin/mount 10.10.10.1:/db-nfs /mnt&lt;br /&gt;&lt;br /&gt;ii) add it to fstab&lt;br /&gt;cat /etc/fstab&lt;br /&gt;10.10.10.1:/db-nfs/    /mnt/db-nfs  nfs rw,hard,intr 0 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1803377495603815987?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1803377495603815987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1803377495603815987&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1803377495603815987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1803377495603815987'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/nfs-mounting-to-share-free-disk-space.html' title='NFS mounting to share free disk space'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3044258099074798539</id><published>2011-05-24T04:44:00.000-07:00</published><updated>2011-05-24T04:49:19.693-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>The maximum allowed size for varchar</title><content type='html'># The maximum width of the varchar type is 65535 across all columns. So the following create table statement fails.&lt;br /&gt;&lt;br /&gt;mysql&gt; create table encrypted ( can_des text, tran_address varchar(300), can_resume varchar(1300), can_remark varchar(65000) ) engine=MyISAM;&lt;br /&gt;ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs&lt;br /&gt;&lt;br /&gt;# We will have to change some columns to text, mediumtext or longtext. I guess the big column like can_remark should be converted to text.&lt;br /&gt;&lt;br /&gt;mysql&gt; create table encrypted ( can_des text, tran_address varchar(300), can_resume varchar(1300), can_remark text ) engine=MyISAM;&lt;br /&gt;Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;&lt;br /&gt;# The key can be added on smaller columns as usual.&lt;br /&gt;&lt;br /&gt;mysql&gt; alter table encrypted add key (tran_address);&lt;br /&gt;Query OK, 0 rows affected (0.05 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;# If I try to add a key on a varchar column that is more than say 700 bytes long, I will get the following warning and a partial index will be silently created which is useless.&lt;br /&gt;&lt;br /&gt;mysql&gt; alter table encrypted add key (can_resume);&lt;br /&gt;Query OK, 0 rows affected, 1 warning (0.03 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;mysql&gt; show warnings;&lt;br /&gt;+---------+------+----------------------------------------------------------+&lt;br /&gt;| Level   | Code | Message                                                  |&lt;br /&gt;+---------+------+----------------------------------------------------------+&lt;br /&gt;| Warning | 1071 | Specified key was too long; max key length is 1000 bytes | &lt;br /&gt;+---------+------+----------------------------------------------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table encrypted\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: encrypted&lt;br /&gt;Create Table: CREATE TABLE `encrypted` (&lt;br /&gt;  `can_des` text,&lt;br /&gt;  `tran_address` varchar(300) default NULL,&lt;br /&gt;  `can_resume` varchar(1300) default NULL,&lt;br /&gt;  `can_remark` text,&lt;br /&gt;  KEY `tran_address` (`tran_address`),&lt;br /&gt;  KEY `can_resume` (`can_resume`(1000))&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;# I will prefer to drop the partial index&lt;br /&gt;&lt;br /&gt;mysql&gt; alter table encrypted drop key can_resume;&lt;br /&gt;Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;# full text index can be built on big varchar and text columns&lt;br /&gt;&lt;br /&gt;mysql&gt; ALTER TABLE encrypted ADD FULLTEXT my_ft (can_des, can_resume, can_remark);&lt;br /&gt;Query OK, 0 rows affected (0.02 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;# finally the create table statement looks like this...&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table encrypted\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: encrypted&lt;br /&gt;Create Table: CREATE TABLE `encrypted` (&lt;br /&gt;  `can_des` text,&lt;br /&gt;  `tran_address` varchar(300) default NULL,&lt;br /&gt;  `can_resume` varchar(1300) default NULL,&lt;br /&gt;  `can_remark` text,&lt;br /&gt;  KEY `tran_address` (`tran_address`),&lt;br /&gt;  FULLTEXT KEY `my_ft` (`can_des`,`can_resume`,`can_remark`)&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.00 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3044258099074798539?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3044258099074798539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3044258099074798539&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3044258099074798539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3044258099074798539'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/maximum-allowed-size-for-varchar.html' title='The maximum allowed size for varchar'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7505762537029052339</id><published>2011-05-18T23:02:00.000-07:00</published><updated>2011-05-26T02:08:11.982-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql FAQ'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>multiple instances of mysql</title><content type='html'>If you want to start mysql using different data directory, the simple way is to change the datadir variable path in my cnf. But there are several disadvantages of doing so. &lt;br /&gt;1) I have to change the my.cnf&lt;br /&gt;2) restart &lt;br /&gt;3) I can not access data from 2 different locations at the same time&lt;br /&gt;4) Does not work as expected with 5.1+ version&lt;br /&gt;&lt;br /&gt;Welcome to mysqld_multi&lt;br /&gt;&lt;br /&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/mysqld-multi.html"&gt;http://dev.mysql.com/doc/refman/5.0/en/mysqld-multi.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Add the following code to my.cnf and restart the mysql service. You can continue to use the data at the default location as you used to before.&lt;br /&gt;&lt;br /&gt;[mysqld_multi]&lt;br /&gt;mysqld     = /usr/bin/mysqld_safe&lt;br /&gt;mysqladmin = /usr/bin/mysqladmin&lt;br /&gt;user       = multi_admin&lt;br /&gt;password   = multipass&lt;br /&gt;&lt;br /&gt;[mysqld2]&lt;br /&gt;socket     = /tmp/mysql.sock2&lt;br /&gt;port       = 3307&lt;br /&gt;pid-file   = /var/lib/mysql2/hostname.pid2&lt;br /&gt;datadir    = /var/lib/mysql2&lt;br /&gt;&lt;br /&gt;[mysqld3]&lt;br /&gt;socket     = /tmp/mysql.sock3&lt;br /&gt;port       = 3308&lt;br /&gt;pid-file   = /var/lib/mysql3/hostname.pid3&lt;br /&gt;datadir    = /var/lib/mysql3&lt;br /&gt;&lt;br /&gt;[mysqld4]&lt;br /&gt;socket     = /tmp/mysql.sock4&lt;br /&gt;port       = 3309&lt;br /&gt;pid-file   = /var/lib/mysql4/hostname.pid4&lt;br /&gt;datadir    = /var/lib/mysql4&lt;br /&gt;&lt;br /&gt;[mysqld6]&lt;br /&gt;socket     = /tmp/mysql.sock6&lt;br /&gt;port       = 3311&lt;br /&gt;pid-file   = /mnt/company-nfs/mysql/hostname.pid6&lt;br /&gt;datadir    = /mnt/company-nfs/mysql&lt;br /&gt;&lt;br /&gt;Now you need to start mysqld_multi instance to initiate the "mysqld6" instance. I have saved the data on nfs partition for the sake of flexibility.&lt;br /&gt;&lt;br /&gt;# mysqld_multi --no-log start 6&lt;br /&gt;mysqld_multi log file version 2.16; run: Thu May 19 10:48:30 2011&lt;br /&gt;&lt;br /&gt;Starting MySQL servers&lt;br /&gt;# Starting mysqld daemon with databases from /mnt/company-nfs/mysql&lt;br /&gt;&lt;br /&gt;I can now use the new mysql instance by using the following credentials...&lt;br /&gt;&lt;br /&gt;mysql -h10.10.10.10 -usome_user -psome_password --socket=/tmp/mysql.sock6 --port=3311&lt;br /&gt;&lt;br /&gt;I can use the other sockets like 2,3 and 4 as well. All I need to do is to create the respective data-directories and change the ownership and permission so that mysql is allowed to read/write to these locations.&lt;br /&gt;&lt;br /&gt;mysqld_multi stop 6&lt;br /&gt;&lt;br /&gt;If the stop command as shown above does not work, try...&lt;br /&gt;&lt;br /&gt;mysqladmin --socket=/tmp/mysql.sock6 shutdown&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7505762537029052339?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7505762537029052339/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7505762537029052339&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7505762537029052339'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7505762537029052339'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/multiple-instances-of-mysql.html' title='multiple instances of mysql'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1198080394639731404</id><published>2011-05-17T20:47:00.000-07:00</published><updated>2011-05-17T20:48:07.209-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>InnoDB monitor</title><content type='html'>If you suspect that due to innodb deadlocks, the application performance is affected, turn on the innodb monitor tool.&lt;br /&gt;&lt;br /&gt;to enable the standard InnoDB Monitor, create the innodb_monitor table:&lt;br /&gt;CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB;&lt;br /&gt;&lt;br /&gt;To stop the Monitor, drop the table:&lt;br /&gt;DROP TABLE innodb_monitor;&lt;br /&gt;&lt;br /&gt;This will save the innodb status to error log.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1198080394639731404?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1198080394639731404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1198080394639731404&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1198080394639731404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1198080394639731404'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/innodb-monitor.html' title='InnoDB monitor'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-9163022051720821206</id><published>2011-05-12T01:34:00.000-07:00</published><updated>2011-05-26T23:18:39.046-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Users without super privileges</title><content type='html'>It is recommended to have 2 types of users. &lt;br /&gt;&lt;br /&gt;1) A user with all the privileges including with grant option. This user is equivalent to root.&lt;br /&gt;grant all on *.* to 'foo'@'%' identified by 'bar' with grant option;&lt;br /&gt;&lt;br /&gt;2) Another set of users is the ones who have all the privileges except "super".&lt;br /&gt;revoke super on *.* from 'foo'@'%';&lt;br /&gt;&lt;br /&gt;There are 3 advantages of having users without "super" access.&lt;br /&gt;1) More secure&lt;br /&gt;2) Read only slave&lt;br /&gt;3) Logging&lt;br /&gt;&lt;br /&gt;a) The first point does not need explanation.&lt;br /&gt;b) When I start a slave in "read-only" mode, all the users without super privileges can only read the data and can not write.&lt;br /&gt;c) When the server is not started in "read-only" mode, we can log the users source access points in a mysql table.&lt;br /&gt;&lt;br /&gt;SET GLOBAL init_connect='create table if not exists test.connect(db_name varchar(100), user_with_ip varchar(100), user_permission varchar(100),&lt;br /&gt;thread_id varchar(100), connect_time datetime) engine=MyISAM; insert into test.connect select @@hostname as db_name, user() as user_with_ip,&lt;br /&gt;current_user() as user_permission, connection_id() as connect_id, now() as connect_time';&lt;br /&gt;&lt;br /&gt;This will help to analyse how many times a particular credential was used. The thread_id can also be linked to binary log extract to know the commands executed by a user in that thread.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-9163022051720821206?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/9163022051720821206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=9163022051720821206&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/9163022051720821206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/9163022051720821206'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/users-without-super-privileges.html' title='Users without super privileges'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1581291770541789038</id><published>2011-05-11T01:33:00.000-07:00</published><updated>2011-05-11T01:35:55.030-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Aspersa to watch CPU load</title><content type='html'>Here is a tool shell script that will collect server info when the CPU load is too high.&lt;br /&gt;&lt;br /&gt;http://aspersa.googlecode.com/svn/html/stalk.html&lt;br /&gt;&lt;br /&gt;The files are usually saved in the /root/user/collected folder.&lt;br /&gt;&lt;br /&gt;cat aspersa.sh&lt;br /&gt;#!/bin/sh&lt;br /&gt;# cron to check CPU load every 5 minutes&lt;br /&gt;# */5 * * * * /home/aspersa.sh &gt; /home/aspersa_success.txt 2 &gt; /home/aspersa_err.txt&lt;br /&gt;# this will collect server info when the CPU load more than 10&lt;br /&gt;&lt;br /&gt;echo "aspersa tool required, download from the following location"&lt;br /&gt;echo "svn checkout http://aspersa.googlecode.com/svn/trunk/ aspersa-read-only"&lt;br /&gt;# default threshold is 10 unless specified from command line&lt;br /&gt;&lt;br /&gt;cpuload=${1:-10}&lt;br /&gt;&lt;br /&gt;mynum=`cat /proc/loadavg | awk '{print $2}' | awk -F"." '{print $1}'`&lt;br /&gt;&lt;br /&gt;if [[ $mynum &lt; $cpuload ]];then&lt;br /&gt;echo "running collect tool"&lt;br /&gt;sh /home/aspersa/collect&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;echo "not running collect tool since CPU load is less than $cpuload"&lt;br /&gt;fi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1581291770541789038?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1581291770541789038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1581291770541789038&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1581291770541789038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1581291770541789038'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/aspersa-to-watch-cpu-load.html' title='Aspersa to watch CPU load'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5466321676041627473</id><published>2011-05-08T21:53:00.001-07:00</published><updated>2011-05-08T21:54:11.447-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Compare table count between 2 schema</title><content type='html'>If I need to compare 2 schemas from the same database, here is the script that will come handy.&lt;br /&gt;&lt;br /&gt;# cat mydiff.sh&lt;br /&gt;#!/bin/sh&lt;br /&gt;db1=${1:-'mydb'}&lt;br /&gt;db2=${2:-'mydb_log'}&lt;br /&gt;echo $db1&lt;br /&gt;mysqlshow $db1 --count &gt; $db1.txt&lt;br /&gt;mysqlshow $db2 --count &gt; $db2.txt&lt;br /&gt;diff $db1.txt $db2.txt --side-by-side --suppress-common-lines&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5466321676041627473?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5466321676041627473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5466321676041627473&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5466321676041627473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5466321676041627473'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/compare-table-count-between-2-schema.html' title='Compare table count between 2 schema'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7463531634486640081</id><published>2011-05-03T03:22:00.001-07:00</published><updated>2011-05-05T23:15:11.861-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Logging records for archival purpose</title><content type='html'>There are times when we need to log all the old values of the table. For e.g. when a user updates his security answer, the old value should be saved in a log table. In other words, if a user changed his answer 4 times, I need to save all those 4 values. I do prefer to create archival tables on slave instead of master. Here is the shell script that will create the exact replica of the schema "account" as "account_log" with all the current data. The account database will get updated as and when there is an update/ insert on master. The log database will keep saving old and new values of each table.&lt;br /&gt;&lt;br /&gt;back_track.sh&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# duplicate schema table to hold the archival values &lt;br /&gt;# change the schema name below that you want to track&lt;br /&gt;schema_name='account'&lt;br /&gt;# username and password to access MySQL&lt;br /&gt;user_name='root'&lt;br /&gt;pass_word='root@123'&lt;br /&gt;&lt;br /&gt;echo "drop database if exists "$schema_name"_log;"&lt;br /&gt;echo "create database if not exists "$schema_name"_log;"&lt;br /&gt;mysql -u$user_name -p$pass_word -Bse"SELECT CONCAT(\"CREATE TABLE "$schema_name"_log.\",TABLE_NAME,\" SELECT * FROM $schema_name.\",TABLE_NAME,\";\") from information_schema.columns WHERE TABLE_SCHEMA = \"$schema_name\" group by TABLE_NAME"&lt;br /&gt;echo "use $schema_name;"&lt;br /&gt;mysql -u$user_name -p$pass_word -Bse"SELECT CONCAT(\"DROP TRIGGER IF EXISTS \",TABLE_NAME, \"_update;\") from information_schema.columns WHERE TABLE_SCHEMA = \"$schema_name\" group by TABLE_NAME"&lt;br /&gt;echo 'DELIMITER $$'&lt;br /&gt;mysql -u$user_name -p$pass_word -Bse"SELECT CONCAT(\"CREATE TRIGGER \",TABLE_NAME,\"_update AFTER UPDATE ON \",TABLE_NAME, \" FOR EACH ROW BEGIN INSERT INTO "$schema_name"_log.\",TABLE_NAME,\" values (\", GROUP_CONCAT(CONCAT(\"NEW.\",COLUMN_NAME)), \"); END;\") from information_schema.columns WHERE TABLE_SCHEMA = \"$schema_name\" group by TABLE_NAME"&lt;br /&gt;mysql -u$user_name -p$pass_word -Bse"SELECT CONCAT(\"CREATE TRIGGER \",TABLE_NAME,\"_insert AFTER INSERT ON \",TABLE_NAME, \" FOR EACH ROW BEGIN INSERT INTO "$schema_name"_log.\",TABLE_NAME,\" values (\", GROUP_CONCAT(CONCAT(\"NEW.\",COLUMN_NAME)), \"); END;\") from information_schema.columns WHERE TABLE_SCHEMA = \"$schema_name\" group by TABLE_NAME"&lt;br /&gt;echo '$$'&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;You can call the script and push the output to mysql using...&lt;br /&gt;sh back_track.sh | mysql -uroot -proot@123 -h10.10.10.65 -P4040&lt;br /&gt;&lt;br /&gt;Let's assume one record of the user table (account schema) was updated. You can check the old and new values from the account_log schema by executing query.&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;The following script will help to know the changes taken place for each column.&lt;br /&gt;&lt;br /&gt;# cat audit.sh&lt;br /&gt;#/bin/sh&lt;br /&gt;tbl_name=${1:-'address'}&lt;br /&gt;mysql -Bse"select id, count(*) as cnt from database_log.$tbl_name group by id having cnt &gt; 1" | while read -r id cnt&lt;br /&gt;do&lt;br /&gt;echo "**************************"&lt;br /&gt;echo "values changed for ID $id"&lt;br /&gt;echo "**************************"&lt;br /&gt;mysql -Bse"select * from database_log.$tbl_name where id = $id\G" | sort -t":" -k1,1 -s | grep -v '^*'&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7463531634486640081?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7463531634486640081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7463531634486640081&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7463531634486640081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7463531634486640081'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/logging-records-for-archival-purpose.html' title='Logging records for archival purpose'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8702800482708755943</id><published>2011-05-01T23:16:00.000-07:00</published><updated>2011-05-01T23:18:40.680-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql FAQ'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Replace into and On duplicate key</title><content type='html'>A detailed analysis of what happens when we use different options to insert/ update a record.&lt;br /&gt;&lt;br /&gt;Here is a sample table...&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  3 |      3 | anthony | london, UK           |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;&lt;br /&gt;We want to insert a new record with emp_id 3, name - anthony and the address should be 'South Africa'. If the record is already present in the DB it should be updated.&lt;br /&gt;&lt;br /&gt;This may look like a simple task, but checking the table structure, it is clear that there is no composite unique index, but separate per column unique keys.&lt;br /&gt;&lt;br /&gt;CREATE TABLE `mykey` (&lt;br /&gt;  `id` int(11) NOT NULL auto_increment,&lt;br /&gt;  `emp_id` int(11) default NULL,&lt;br /&gt;&lt;br /&gt;  `name` varchar(100) default NULL,&lt;br /&gt;  `address` varchar(100) default NULL,&lt;br /&gt;  PRIMARY KEY  (`id`),&lt;br /&gt;  UNIQUE KEY `emp_id` (`emp_id`),&lt;br /&gt;  UNIQUE KEY `name` (`name`)&lt;br /&gt;) ENGINE=InnoDB&lt;br /&gt;&lt;br /&gt;The challenge is to write an insert/ update statement that will satisfy all constraint and will fail predictably only in certain cases.&lt;br /&gt;&lt;br /&gt;1) "insert ignore" will prefer not to do anything.&lt;br /&gt;2) "replace into" may look like the best choice, but it will also change the auto_incremented ID and has some issues when there is more than one unique key.&lt;br /&gt;For e.g. in the following example, while trying to insert emp_id 3 with name - akbar, it actually removed one row.&lt;br /&gt;&lt;br /&gt;3) I guess the "on duplicate key update " clause is the right choice. It does not change the auto_id while updating the record. And even if there are no composite unique indexes in the table, it works as if they are present.&lt;br /&gt;&lt;br /&gt;mysql&gt; drop table if exists mykey;&lt;br /&gt;Query OK, 0 rows affected (0.02 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; create table mykey(id int not null auto_increment, emp_id int, name varchar(100), address varchar(100), primary key (id), unique(emp_id), unique(name)) engine=InnoDB;&lt;br /&gt;Query OK, 0 rows affected (0.13 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into mykey (emp_id, name, address) values (1, 'amar', 'hyderabad, AP, india') ;&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into mykey (emp_id, name, address) values (2, 'akbar', 'karachi, pakistan');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into mykey (emp_id, name, address) values (3, 'anthony', 'london, UK') ;&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; start transaction;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; savepoint savepoint_one;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  3 |      3 | anthony | london, UK           |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;# Case 1: "insert ignore"&lt;br /&gt;&lt;br /&gt;mysql&gt; insert ignore into mykey (emp_id, name, address) values (3, 'anthony', 'South Africa') ;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  3 |      3 | anthony | london, UK           |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;# Case 2: "replace into"&lt;br /&gt;&lt;br /&gt;mysql&gt; replace into mykey (emp_id, name, address) values (3, 'anthony', 'South Africa') ;&lt;br /&gt;Query OK, 2 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  4 |      3 | anthony | South Africa         |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; rollback to savepoint_one;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  3 |      3 | anthony | london, UK           |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; replace into mykey (emp_id, name, address) values (3, 'akbar', 'South Africa') ;&lt;br /&gt;Query OK, 3 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+-------+----------------------+&lt;br /&gt;| id | emp_id | name  | address              |&lt;br /&gt;+----+--------+-------+----------------------+&lt;br /&gt;|  1 |      1 | amar  | hyderabad, AP, india |&lt;br /&gt;|  5 |      3 | akbar | South Africa         |&lt;br /&gt;+----+--------+-------+----------------------+&lt;br /&gt;2 rows in set (0.00 sec)&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;# Case 3: "on duplicate key"&lt;br /&gt;&lt;br /&gt;mysql&gt; rollback to savepoint_one;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  3 |      3 | anthony | london, UK           |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;3 rows in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into mykey (emp_id, name, address) values (3, 'akbar', 'South Africa') on duplicate key update emp_id = 3, name = 'akbar', address='South Africa' ;&lt;br /&gt;ERROR 1062 (23000): Duplicate entry 'akbar' for key 3&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into mykey (emp_id, name, address) values (3, 'akbar', 'South Africa') on duplicate key update emp_id = 3, name = 'anthony', address='South Africa' ;&lt;br /&gt;Query OK, 2 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mykey;&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;| id | emp_id | name    | address              |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;|  1 |      1 | amar    | hyderabad, AP, india |&lt;br /&gt;|  2 |      2 | akbar   | karachi, pakistan    |&lt;br /&gt;|  3 |      3 | anthony | South Africa         |&lt;br /&gt;+----+--------+---------+----------------------+&lt;br /&gt;3 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/3043709-8702800482708755943?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8702800482708755943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8702800482708755943&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8702800482708755943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8702800482708755943'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/05/replace-into-and-on-duplicate-key.html' title='Replace into and On duplicate key'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1528370377556290900</id><published>2011-04-25T01:23:00.000-07:00</published><updated>2011-04-25T01:30:28.357-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Saving images in a table</title><content type='html'>The binary data should not be saved in a table. It should be saved as a file on the application server and only the name and path should be saved in the table. If you must save the image in a table, you can do so in a normalized way. Here is an example...&lt;br /&gt;&lt;br /&gt;This is how a typical table that saves the binary data like user images look like.&lt;br /&gt;&lt;br /&gt;CREATE TABLE `user_info` (&lt;br /&gt;  `id` int(11) not null auto_increment,&lt;br /&gt;  `name` varchar(100),&lt;br /&gt;  `address1` varchar(256),&lt;br /&gt;  `city` varchar(256),&lt;br /&gt;  `country` varchar(256),&lt;br /&gt;  `acc_no` varchar(256),&lt;br /&gt;  `home_phone` varchar(256),&lt;br /&gt;  `office_phone` varchar(256),&lt;br /&gt;  `mobile_no` varchar(256),&lt;br /&gt;  `date_of_birth` varchar(256),&lt;br /&gt;  `age` varchar(256),&lt;br /&gt;  `user_photo` blob,&lt;br /&gt;   primary key (id)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;&lt;br /&gt;In order to normalize the data, we need to save the images in a separate table. and link the image using the primary key ID of user_info table.&lt;br /&gt;&lt;br /&gt;CREATE TABLE `user_pic` (&lt;br /&gt;  `id` int(11) NOT NULL auto_increment,&lt;br /&gt;  `myfile` longblob,&lt;br /&gt;  `dbname` varchar(100),&lt;br /&gt;  `tblname` varchar(100),&lt;br /&gt;   user_id int,&lt;br /&gt;  PRIMARY KEY  (`id`),&lt;br /&gt;  FOREIGN KEY (`user_id`) references user_info (id) &lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;The following shell script will move the user photos from user_info table to user_pic table and link it back to the parent table.&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;mynum=`date '+%m%d%H%M%S'`&lt;br /&gt;num=1&lt;br /&gt;&lt;br /&gt;while (( num &lt; 100 ))&lt;br /&gt;do&lt;br /&gt;mysql test -uroot -pPasswd -e"select user_photo into dumpfile '/tmp/myfile_mar_$mynum_$num.png' from user_info where id = $num"&lt;br /&gt;&lt;br /&gt;if [[ -s /tmp/myfile_mar_$mynum_$num.png ]];then&lt;br /&gt;mysql test -uroot -pPasswd -e"insert into user_pic values (NULL, load_file('/tmp/myfile_mar_$mynum_$num.png'), database(), 'user_info', $num)"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;let num+=1&lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Once the script is successfully run, drop the column "user_photo" from the user_info table.&lt;br /&gt;ALTER TABLE user_info DROP COLUMN user_photo;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1528370377556290900?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1528370377556290900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1528370377556290900&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1528370377556290900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1528370377556290900'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/04/saving-images-in-table.html' title='Saving images in a table'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6153226544073867929</id><published>2011-04-18T05:25:00.000-07:00</published><updated>2011-04-18T05:27:15.815-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Escaping in MySQL</title><content type='html'>Usually Mysql returns the text as is and does not escape the special characters.&lt;br /&gt;&lt;br /&gt;# mysql -ushantanu -pshantanu@123 -Bse"select name from test.todel"&lt;br /&gt;shantanu's&lt;br /&gt;amar"s&lt;br /&gt;&lt;br /&gt;If I need the following output, I will have to write a small shell script.&lt;br /&gt;&lt;br /&gt;shantanu\'s&lt;br /&gt;amar\"s&lt;br /&gt;&lt;br /&gt;You can use mysql_real_escape_string if you are comfortable with PHP, but if you insist on shell, here is a solution assuming name is the second column in the table.&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;mysqldump -ushantanu -pshantanu@123 test todel --compact --skip-extended-insert --no-create-info &gt; tofile.txt&lt;br /&gt;&lt;br /&gt;for customer in `sed -rn 's/.*\(//;s/\).*//p' tofile.txt | awk -F"," '{print $2}' | sed "s/^'//" | sed "s/'$//"`&lt;br /&gt;do&lt;br /&gt;echo $customer&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6153226544073867929?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6153226544073867929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6153226544073867929&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6153226544073867929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6153226544073867929'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/04/escaping-in-mysql.html' title='Escaping in MySQL'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7335945993038100263</id><published>2011-04-06T04:12:00.000-07:00</published><updated>2011-04-06T04:13:16.296-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>MySQL and RAMdisk to make queries faster</title><content type='html'>Here is how you get MySQL to use a 1G size tmpfs. &lt;br /&gt;http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_tmpdir&lt;br /&gt;&lt;br /&gt;0. mkdir -p /db/tmpfs01 &amp;&amp; chown mysql:mysql /db/tmpfs01&lt;br /&gt;1. mount tmpfs /db/tmpfs01 -t tmpfs -o size=1G&lt;br /&gt;3. edit my.cnf file and add: tmpdir = /db/tmpfs01&lt;br /&gt;4. restart MySQL&lt;br /&gt;&lt;br /&gt;To have persistent tmpfs with reboot put the following into /etc/fstab. On this system the mysql user is uid/gid of 27, yours might vary so adjust accordingly.&lt;br /&gt;tmpfs /db/tmpfs01 tmpfs rw,uid=27,gid=27,size=1G,nr_inodes=10k,mode=0755 0 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7335945993038100263?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7335945993038100263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7335945993038100263&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7335945993038100263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7335945993038100263'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/04/mysql-and-ramdisk-to-make-queries.html' title='MySQL and RAMdisk to make queries faster'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3284275935985829833</id><published>2011-04-05T21:37:00.000-07:00</published><updated>2011-04-05T21:39:26.201-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Controlling mysql access using firewall</title><content type='html'>If I want to allow a new application server to access mysql on current 3306 port, I need the following command&lt;br /&gt;&lt;br /&gt;iptables -I INPUT 13 -s 111.222.333.444 -p tcp --dport 3306 -j ACCEPT&lt;br /&gt;&lt;br /&gt;I can check if the rule is set as expected.&lt;br /&gt;&lt;br /&gt;iptables -nvL&lt;br /&gt;&lt;br /&gt;   4   240 ACCEPT     tcp  --  *      *       111.222.333.444      0.0.0.0/0           tcp dpt:3306&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3284275935985829833?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3284275935985829833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3284275935985829833&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3284275935985829833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3284275935985829833'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/04/controlling-mysql-access-using-firewall.html' title='Controlling mysql access using firewall'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2956640017464281980</id><published>2011-03-24T01:36:00.000-07:00</published><updated>2011-03-24T01:37:51.321-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Hacking FRM files to switch numeric data types</title><content type='html'>In order to change any numeric data type to UNSIGNED here is a simple and basic alter table statement that needs to be executed.&lt;br /&gt;&lt;br /&gt;alter table frm_hack modify id tinyint unsigned;&lt;br /&gt;&lt;br /&gt;But if the table is big, it will take a lot of time and here is a frm hack suggested...&lt;br /&gt;&lt;br /&gt;http://www.facebook.com/note.php?note_id=10150115679045933&lt;br /&gt;&lt;br /&gt;And here is how it works:&lt;br /&gt;&lt;br /&gt;mysql&gt; create table frm_hack(id tinyint, name varchar(100), primary key (id)) engine=InnoDB;&lt;br /&gt;Query OK, 0 rows affected (0.10 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into frm_hack values (1, 'shantanu'), (2, 'john'), (121, 'ram'), (234, 'shyam');&lt;br /&gt;Query OK, 4 rows affected, 1 warning (0.03 sec)&lt;br /&gt;Records: 4  Duplicates: 0  Warnings: 1&lt;br /&gt;&lt;br /&gt;mysql&gt; create table frm_hack_new (id tinyint unsigned, name varchar(100), primary key (id)) engine=InnoDB;&lt;br /&gt;Query OK, 0 rows affected (0.08 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; \q&lt;br /&gt;Bye&lt;br /&gt;&lt;br /&gt;[root@localhost test]# cp frm_hack_new.frm frm_hack.frm&lt;br /&gt;cp: overwrite `frm_hack.frm'? y&lt;br /&gt;&lt;br /&gt;[root@localhost test]# mysql test&lt;br /&gt;&lt;br /&gt;Type 'help;' or '\h' for help. Type '\c' to clear the buffer.&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table frm_hack\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: frm_hack&lt;br /&gt;Create Table: CREATE TABLE `frm_hack` (&lt;br /&gt;  `id` tinyint(4) NOT NULL default '0',&lt;br /&gt;  `name` varchar(100) default NULL,&lt;br /&gt;  PRIMARY KEY  (`id`)&lt;br /&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table frm_hack_new\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: frm_hack_new&lt;br /&gt;Create Table: CREATE TABLE `frm_hack_new` (&lt;br /&gt;  `id` tinyint(3) unsigned NOT NULL default '0',&lt;br /&gt;  `name` varchar(100) default NULL,&lt;br /&gt;  PRIMARY KEY  (`id`)&lt;br /&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from frm_hack;&lt;br /&gt;+-----+----------+&lt;br /&gt;| id  | name     |&lt;br /&gt;+-----+----------+&lt;br /&gt;|   1 | shantanu | &lt;br /&gt;|   2 | john     | &lt;br /&gt;| 121 | ram      | &lt;br /&gt;| 127 | shyam    | &lt;br /&gt;+-----+----------+&lt;br /&gt;4 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; flush tables;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table frm_hack\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: frm_hack&lt;br /&gt;Create Table: CREATE TABLE `frm_hack` (&lt;br /&gt;  `id` tinyint(3) unsigned NOT NULL default '0',&lt;br /&gt;  `name` varchar(100) default NULL,&lt;br /&gt;  PRIMARY KEY  (`id`)&lt;br /&gt;) ENGINE=InnoDB DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into frm_hack values (213, 'abc');&lt;br /&gt;Query OK, 1 row affected (0.02 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from frm_hack;&lt;br /&gt;+-----+----------+&lt;br /&gt;| id  | name     |&lt;br /&gt;+-----+----------+&lt;br /&gt;| 213 | abc      | &lt;br /&gt;|   1 | shantanu | &lt;br /&gt;|   2 | john     | &lt;br /&gt;| 121 | ram      | &lt;br /&gt;| 127 | shyam    | &lt;br /&gt;+-----+----------+&lt;br /&gt;5 rows in set (0.01 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2956640017464281980?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2956640017464281980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2956640017464281980&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2956640017464281980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2956640017464281980'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/03/hacking-frm-files-to-switch-numeric.html' title='Hacking FRM files to switch numeric data types'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3973600579209156602</id><published>2011-03-20T22:01:00.001-07:00</published><updated>2011-03-20T22:01:55.739-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Finding data / comma in a table record</title><content type='html'>Here is an easy trick to find the table names where comma "," is being used. I will export the data in "tab" delimited format using maatkit and then look for the comma.&lt;br /&gt;&lt;br /&gt;rm -rf /pdump/ &amp;&amp; mkdir /pdump/&lt;br /&gt;chmod 777 /pdump/&lt;br /&gt;&lt;br /&gt;/usr/bin/mk-parallel-dump --no-gzip --base-dir '/pdump' --databases 'my_db' --tab&lt;br /&gt;&lt;br /&gt;# grep -r ',' *.txt | awk -F":" '{print $1}' | sort -u | awk -F"." '{print $1}'&lt;br /&gt;address&lt;br /&gt;address_log&lt;br /&gt;&lt;br /&gt;The 2 tables address and address_log in the my_db database has the comma somewhere in its record. This tip can be used to find a word or phrase as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3973600579209156602?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3973600579209156602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3973600579209156602&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3973600579209156602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3973600579209156602'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/03/finding-data-comma-in-table-record.html' title='Finding data / comma in a table record'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-143522992983237119</id><published>2011-03-17T04:44:00.000-07:00</published><updated>2011-03-17T05:17:43.093-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Batch processing</title><content type='html'>Let's assume you want to update the second column of the table to upper case. The following SQL statement will do the needful.&lt;br /&gt;update tbl set second_col = upper(second_col) &lt;br /&gt;&lt;br /&gt;But if you want to do it in some other way, or if there are more complex processes involved where an SQL won't work, then here is the solution. This is 4 steps procedure to change the data. An utility called "maatkit" is required for this.&lt;br /&gt;&lt;br /&gt;##### create directory and make it writable #####&lt;br /&gt;&lt;br /&gt;# cd /home/&lt;br /&gt;# rm -rf /pdump/ &lt;br /&gt;# mkdir /pdump&lt;br /&gt;# chmod 777 /pdump/*&lt;br /&gt;&lt;br /&gt;##### Download data in TAB or CSV format #####&lt;br /&gt;&lt;br /&gt;/usr/bin/mk-parallel-dump -h'localhost' --no-gzip --base-dir '/pdump' --databases 'myDB' --tables 'country' --csv&lt;br /&gt;CHUNK  TIME  EXIT  SKIPPED DATABASE.TABLE&lt;br /&gt;   db  0.02     0        0 myDB       &lt;br /&gt;  all  0.02     0        0 -             &lt;br /&gt;&lt;br /&gt;##### Change the third column data from one encryption to another #####&lt;br /&gt;&lt;br /&gt;sh /home/shantanu/line.sh &gt; /pdump/myDB/temp.txt&lt;br /&gt;mv /pdump/myDB/temp.txt /pdump/myDB/country.000000.txt&lt;br /&gt;&lt;br /&gt;##### drop the table insert the updated data back to the table #####&lt;br /&gt;&lt;br /&gt;/usr/bin/mk-parallel-restore -h'localhost' --database 'myDB' --tables 'country' '/pdump' --csv&lt;br /&gt;    1 tables,     2 files,     1 successes,  0 failures,   0.48 wall-clock time,   0.48 load time&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;The line.sh shell script looks like this...&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# read file line by line&lt;br /&gt;file="/pdump/myDB/country.000000.txt"&lt;br /&gt;while read line&lt;br /&gt;do&lt;br /&gt;# select the second column&lt;br /&gt;mycol=`echo $line | awk -F"," '{print $2}'`&lt;br /&gt;&lt;br /&gt;# convert it to upper case&lt;br /&gt;mycol_new=`echo $mycol | tr "[:lower:]" [:upper:]`&lt;br /&gt;&lt;br /&gt;# do some more java processing with the value&lt;br /&gt;# replace the upper case text in the text file&lt;br /&gt;echo $line | awk -v var="$mycol_new" -F"," '{print $1 ","  var  "," $3 "," $4 "," $5 "," $6 "," $7 "," $8}'&lt;br /&gt;&lt;br /&gt;done &lt; $file&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-143522992983237119?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/143522992983237119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=143522992983237119&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/143522992983237119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/143522992983237119'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/03/batch-processing.html' title='Batch processing'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8174142929665913157</id><published>2011-03-09T01:25:00.000-08:00</published><updated>2011-03-09T01:29:38.867-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>Mysql Monitor</title><content type='html'>mysql monitor is the nagios of Database. It is especially useful when you have a bunch of mysql DB servers to manage.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.mysql.com/products/enterprise/monitor.html"&gt;http://www.mysql.com/products/enterprise/monitor.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here are 8 steps to enable the monitoring agent on the DB server. It is assumed that the monitor server is already configured and active on a server (for e.g. 10.10.10.63)&lt;br /&gt;&lt;br /&gt;1) sudo root&lt;br /&gt;2) download agent &lt;br /&gt;3) Change file permissions&lt;br /&gt;chmod +x mysqlmonitoragent-2.3.1.2044-linux-glibc2.3-x86-64bit-installer.bin&lt;br /&gt;&lt;br /&gt;4) Run file&lt;br /&gt;[root@localhost]# ./mysqlmonitoragent-2.3.1.2044-linux-glibc2.3-x86-64bit-installer.bin&lt;br /&gt;&lt;br /&gt;5) Start agent&lt;br /&gt;/etc/init.d/mysql-monitor-agent start&lt;br /&gt;&lt;br /&gt;6) check status&lt;br /&gt;ps -ef | grep monitor&lt;br /&gt;&lt;br /&gt;7) check log&lt;br /&gt;cat /opt/mysql/enterprise/agent/mysql-monitor-agent.log&lt;br /&gt;&lt;br /&gt;8) create mysql user for e.g.&lt;br /&gt;mysql&gt; grant all on *.* to 'agent'@'%' identified by 'agent';&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;The following options must be selected very carefully or else monitor will not work as expected.&lt;br /&gt;&lt;br /&gt;Installation directory&lt;br /&gt;Installation directory [/opt/mysql/enterprise/agent]: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How will the agent connect to the database it is monitoring?&lt;br /&gt;[1] TCP/IP&lt;br /&gt;[2] Socket&lt;br /&gt;Please choose an option [1] : 1&lt;br /&gt;&lt;br /&gt;----------------------------------------------------------------------------&lt;br /&gt;Components to Install&lt;br /&gt;&lt;br /&gt;Monitoring:&lt;br /&gt;Enable the Agent to monitor a MySQL Server [Y/n]: Y&lt;br /&gt;&lt;br /&gt;Query Analyzer:&lt;br /&gt;Enable the Aggregator to aggregate Query Analyzer data from an external source [y/N]: N&lt;br /&gt;Enable MySQL Proxy to collect and aggregate Query Analyzer data [y/N]: y&lt;br /&gt;&lt;br /&gt;----------------------------------------------------------------------------&lt;br /&gt;Monitored Database Information&lt;br /&gt;&lt;br /&gt;MySQL hostname or IP address [127.0.0.1]: &lt;br /&gt;&lt;br /&gt;Validate MySQL hostname or IP address [y/N]: N&lt;br /&gt;&lt;br /&gt;MySQL Port [3306]: &lt;br /&gt;&lt;br /&gt;MySQL Username [agent]: agent&lt;br /&gt;&lt;br /&gt;MySQL Password :&lt;br /&gt;Re-enter :&lt;br /&gt;----------------------------------------------------------------------------&lt;br /&gt;Agent User Account Creation&lt;br /&gt;&lt;br /&gt;[1] Yes, use the credentials below to create the Agent's user account&lt;br /&gt;[2] No, I've already created the account and I'm sure it's correct&lt;br /&gt;Please choose an option [1] : 2&lt;br /&gt;&lt;br /&gt;----------------------------------------------------------------------------&lt;br /&gt;MySQL Enterprise Monitor Options&lt;br /&gt;&lt;br /&gt;Hostname or IP address []: 10.10.10.63&lt;br /&gt;&lt;br /&gt;Tomcat Server Port [18080]: &lt;br /&gt;&lt;br /&gt;Tomcat SSL Port [18443]: &lt;br /&gt;&lt;br /&gt;Use SSL? [y/N]: y&lt;br /&gt;&lt;br /&gt;Agent Username [agent]: agent&lt;br /&gt;&lt;br /&gt;Agent Password :&lt;br /&gt;Re-enter :&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8174142929665913157?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8174142929665913157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8174142929665913157&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8174142929665913157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8174142929665913157'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/03/mysql-monitor.html' title='Mysql Monitor'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-856678011433969399</id><published>2011-02-09T23:02:00.000-08:00</published><updated>2011-02-09T23:03:20.083-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Update Slaves those are out of sync</title><content type='html'>You can use a simple MySQL trick to get all the rows of a table to replicate through to slaves. The idea is to dump the table, delete the rows, then reload it again. The delete and subsequent reload replicate out to slaves, after which everything is consistent again. Let's say we have a table called tpcb.history that needs to be fixed. Login with mysql and run the following commands:&lt;br /&gt;&lt;br /&gt;BEGIN;&lt;br /&gt;SELECT * FROM tpcb.history &lt;br /&gt;  INTO OUTFILE '/tmp/tpcb.history.dmp' FOR UPDATE;&lt;br /&gt;DELETE FROM tpcb.history;&lt;br /&gt;LOAD DATA INFILE '/tmp/tpcb.history.dmp' REPLACE&lt;br /&gt;  INTO TABLE tpcb.history FIELDS TERMINATED BY '\t'&lt;br /&gt;  LINES TERMINATED BY '\n';&lt;br /&gt;COMMIT;&lt;br /&gt;&lt;br /&gt;You can do the reload several ways in MySQL, but this particular code has some advantages over other approaches, such as using LOCK TABLES. First, it uses a transaction, so if something goes wrong the changes roll back and you do not lose your data. Second, the SELECT ... FOR UPDATE locks your data and ensures serialization.  You can run this while applications are running without problems.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-856678011433969399?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/856678011433969399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=856678011433969399&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/856678011433969399'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/856678011433969399'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/02/update-slaves-those-are-out-of-sync.html' title='Update Slaves those are out of sync'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2343675493357939732</id><published>2011-02-09T00:19:00.000-08:00</published><updated>2011-02-09T23:03:47.700-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql bug'/><title type='text'>Performance problem with Innodb and DROP TABLE</title><content type='html'>innodb_file_per_table options is commonly used these days and it does no doubt help to improve the performance a little bit ( may be 5-10%). But using this option coupled with the large buffer pool will make dropping the tables and schemas very difficult. It takes a lot of time, in some cases hours and it does not allow mysql process other queries. This seems to be a serious bug and I guess one should try to avoid InnoDB table types if the table is expected to be dropped or if it is expected to be very large. Deleting large recordset also takes time and that needs to be addressed as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2343675493357939732?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2343675493357939732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2343675493357939732&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2343675493357939732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2343675493357939732'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/02/performance-problem-with-innodb-and.html' title='Performance problem with Innodb and DROP TABLE'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2450864278177589623</id><published>2011-01-28T03:36:00.000-08:00</published><updated>2011-01-28T03:37:12.093-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Updatable views</title><content type='html'>You can use the "with check option" property of view to create constraint that will do the needful of checking the data. &lt;br /&gt;For e.g. if I want to allow the ID 1 into the table parent, I can use "enum" datatype or create a view with appropriate where clause.&lt;br /&gt;&lt;br /&gt;drop table child;&lt;br /&gt;drop table parent;&lt;br /&gt;&lt;br /&gt;CREATE TABLE parent(&lt;br /&gt;`ID` int(11) default NULL,&lt;br /&gt;`name` varchar(100) default NULL,&lt;br /&gt;`city` varchar(100) default NULL,&lt;br /&gt;primary key (name)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;&lt;br /&gt;create table child(&lt;br /&gt;username varchar(100) not null,&lt;br /&gt;FOREIGN KEY (username) REFERENCES parent(name) on update cascade,&lt;br /&gt;primary key (username)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;&lt;br /&gt;insert into parent values (1, 'abc', 'delhi');&lt;br /&gt;insert into child values ('abc');&lt;br /&gt;&lt;br /&gt;create or replace view myview as select * from parent where ID &gt; 0 and ID &lt; 2 with check option;&lt;br /&gt;&lt;br /&gt;mysql&gt;insert into myview values (3, 'qqabc', 'wwdelhi');&lt;br /&gt;ERROR 1369 (HY000): CHECK OPTION failed 'test.myview'&lt;br /&gt;&lt;br /&gt;mysql&gt;insert into myview values (1, 'qqabc', 'wwdelhi');&lt;br /&gt;Query OK, 1 row affected (0.02 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2450864278177589623?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2450864278177589623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2450864278177589623&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2450864278177589623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2450864278177589623'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/01/updatable-views.html' title='Updatable views'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3806215116462881285</id><published>2011-01-18T23:05:00.000-08:00</published><updated>2011-01-18T23:06:40.156-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql case study'/><title type='text'>MySQL Case Study - 182</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Finding rows those are NOT 10 digits long&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;I need to find the rows those are not 10 digits in length and must include a digit and not a alphabet.&lt;br /&gt;&lt;br /&gt;CREATE TABLE mobile (mno varchar(100) default NULL);&lt;br /&gt;INSERT INTO mobile VALUES ('223456780'),('2234567890'),('4234567890'),('6234567890'),('22345678aaaa0'),('123456789a');&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mobile;&lt;br /&gt;+---------------+&lt;br /&gt;| mno           |&lt;br /&gt;+---------------+&lt;br /&gt;| 223456780     | &lt;br /&gt;| 2234567890    | &lt;br /&gt;| 4234567890    | &lt;br /&gt;| 6234567890    | &lt;br /&gt;| 22345678aaaa0 | &lt;br /&gt;| 123456789a    | &lt;br /&gt;+---------------+&lt;br /&gt;6 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mobile WHERE length(mno) != 10;&lt;br /&gt;+---------------+&lt;br /&gt;| mno           |&lt;br /&gt;+---------------+&lt;br /&gt;| 223456780     | &lt;br /&gt;| 22345678aaaa0 | &lt;br /&gt;+---------------+&lt;br /&gt;2 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from mobile WHERE mno NOT RLIKE '[0-9]{10}';&lt;br /&gt;+---------------+&lt;br /&gt;| mno           |&lt;br /&gt;+---------------+&lt;br /&gt;| 223456780     | &lt;br /&gt;| 22345678aaaa0 | &lt;br /&gt;| 123456789a    | &lt;br /&gt;+---------------+&lt;br /&gt;3 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/3043709-3806215116462881285?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3806215116462881285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3806215116462881285&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3806215116462881285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3806215116462881285'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/01/mysql-case-study-182.html' title='MySQL Case Study - 182'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6957022903117983585</id><published>2011-01-12T01:45:00.000-08:00</published><updated>2011-01-12T01:54:25.354-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>One more way to select</title><content type='html'>I can write the following query if I know the exact column name where I expect to find the matching value.&lt;br /&gt;select * from parent where city = 'Delhi'&lt;br /&gt;But it is interesting to know that grep can be used at the command prompt that will return only the records where that appear.&lt;br /&gt;&lt;br /&gt;mysql&gt;pager grep Delhi&lt;br /&gt;PAGER set to 'grep Delhi'&lt;br /&gt;&lt;br /&gt;mysql&gt;select * from parent;&lt;br /&gt;|    2 | Amar    | Delhi  | &lt;br /&gt;|    5 | Akbar   | Delhi  | &lt;br /&gt;|    8 | Anthony | Delhi  | &lt;br /&gt;10 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;pager&lt;br /&gt;Default pager wasn't set, using stdout.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6957022903117983585?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6957022903117983585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6957022903117983585&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6957022903117983585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6957022903117983585'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/01/one-more-way-to-select.html' title='One more way to select'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8035617719224817760</id><published>2011-01-06T03:43:00.000-08:00</published><updated>2011-01-06T03:56:38.845-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Top N records per group</title><content type='html'>Selecting top N records per group is not as easy as it seems. The query may get as complex as you want. &lt;br /&gt;&lt;br /&gt;http://code.openark.org/blog/mysql/sql-selecting-top-n-records-per-group&lt;br /&gt;&lt;br /&gt;Here is how I would solve it by taking help of composite index with one of the column being auto_id.&lt;br /&gt;InnoDB table types do not support such indexes though.&lt;br /&gt;&lt;br /&gt;drop table if exists Country_sort;&lt;br /&gt;&lt;br /&gt; CREATE TABLE `Country_sort` (&lt;br /&gt;id int not null auto_increment,&lt;br /&gt;  `Code` char(3) NOT NULL default '',&lt;br /&gt;  `Name` char(52) NOT NULL default '',&lt;br /&gt;  `Continent` enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',&lt;br /&gt;  `Region` char(26) NOT NULL default '',&lt;br /&gt;  `SurfaceArea` float(10,2) NOT NULL default '0.00',&lt;br /&gt;  `IndepYear` smallint(6) default NULL,&lt;br /&gt;  `Population` int(11) NOT NULL default '0',&lt;br /&gt;  `LifeExpectancy` float(3,1) default NULL,&lt;br /&gt;  `GNP` float(10,2) default NULL,&lt;br /&gt;  `GNPOld` float(10,2) default NULL,&lt;br /&gt;  `LocalName` char(45) NOT NULL default '',&lt;br /&gt;  `GovernmentForm` char(45) NOT NULL default '',&lt;br /&gt;  `HeadOfState` char(60) default NULL,&lt;br /&gt;  `Capital` int(11) default NULL,&lt;br /&gt;  `Code2` char(2) NOT NULL default '',&lt;br /&gt;  PRIMARY KEY  (Continent, id)&lt;br /&gt;) ENGINE=MyISAM;&lt;br /&gt;&lt;br /&gt;insert into Country_sort select NULL, Code, Name, Continent, Region, SurfaceArea, IndepYear, Population, LifeExpectancy, GNP, GNPOld, LocalName, GovernmentForm, HeadOfState, Capital, Code2 from Country order by Continent, SurfaceArea desc;&lt;br /&gt;&lt;br /&gt;select Continent, name from Country_sort where ID = 1 order by Continent;&lt;br /&gt;&lt;br /&gt;select Continent, name, SurfaceArea, Population from Country_sort where ID &lt;= 5 order by Continent, SurfaceArea desc;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8035617719224817760?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8035617719224817760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8035617719224817760&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8035617719224817760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8035617719224817760'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/01/top-n-records-per-group.html' title='Top N records per group'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2217253607590553822</id><published>2011-01-05T00:50:00.001-08:00</published><updated>2011-01-05T00:52:10.129-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Binary collation and text comparison</title><content type='html'>MySQL by default, ignores capital and small letters in the data:&lt;br /&gt;&lt;br /&gt;mysql&gt; create table todel (description varchar(100) COLLATE utf8_bin);&lt;br /&gt;Query OK, 0 rows affected (0.02 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into todel (description) values ('This is MIXED case');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from todel where description like '%MIXED%';&lt;br /&gt;+--------------------+&lt;br /&gt;| description        |&lt;br /&gt;+--------------------+&lt;br /&gt;| This is MIXED case | &lt;br /&gt;+--------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from todel where description like '%mixed%';&lt;br /&gt;+--------------------+&lt;br /&gt;| description        |&lt;br /&gt;+--------------------+&lt;br /&gt;| This is MIXED case | &lt;br /&gt;+--------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;If you want mysql to consider the case, you have to use the "binary" keyword as shown below. The comparison is now case sensitive.&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from todel where binary description like '%mixed%';&lt;br /&gt;Empty set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from todel where binary description like '%MIXED%';&lt;br /&gt;+--------------------+&lt;br /&gt;| description        |&lt;br /&gt;+--------------------+&lt;br /&gt;| This is MIXED case | &lt;br /&gt;+--------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;If you want all the queries on that column (for e.g. description) to be case sensitive, change the collation to binary in the create table statement.&lt;br /&gt;&lt;br /&gt;mysql&gt; create table todel (description varchar(100) COLLATE utf8_bin);&lt;br /&gt;Query OK, 0 rows affected (0.04 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into todel (description) values ('This is MIXED case');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from todel where description like '%mixed%';&lt;br /&gt;Empty set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from todel where description like '%MIXED%';&lt;br /&gt;+--------------------+&lt;br /&gt;| description        |&lt;br /&gt;+--------------------+&lt;br /&gt;| This is MIXED case | &lt;br /&gt;+--------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;It is recommended NOT to use the utf8_bin collation type for any column. If your table already has one, get rid of it using "alter table modify" statement.&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table todel\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: todel&lt;br /&gt;Create Table: CREATE TABLE `todel` (&lt;br /&gt;  `description` varchar(100) character set utf8 collate utf8_bin default NULL&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;br /&gt;&lt;br /&gt;mysql&gt; alter table todel modify description varchar(100);&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table todel\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: todel&lt;br /&gt;Create Table: CREATE TABLE `todel` (&lt;br /&gt;  `description` varchar(100) default NULL&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;br /&gt;&lt;br /&gt;mysql&gt; alter table todel modify description varchar(100) collate utf8_bin;&lt;br /&gt;&lt;br /&gt;mysql&gt; show create table todel\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: todel&lt;br /&gt;Create Table: CREATE TABLE `todel` (&lt;br /&gt;  `description` varchar(100) character set utf8 collate utf8_bin default NULL&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2217253607590553822?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2217253607590553822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2217253607590553822&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2217253607590553822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2217253607590553822'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/01/binary-collation-and-text-comparison.html' title='Binary collation and text comparison'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6562249656258338182</id><published>2011-01-03T21:20:00.000-08:00</published><updated>2011-01-20T22:37:21.567-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Savepoints in transaction</title><content type='html'>rollbacks usually let you go back to the start of the transaction, but not necessarily if you use savepoints.&lt;br /&gt;mysql&gt; rollback;&lt;br /&gt;&lt;br /&gt;will undo all the statements till the beginning of the transaction, whereas &lt;br /&gt;mysql&gt; rollback to savepoint savepoint_one;&lt;br /&gt;&lt;br /&gt;Will revert back to the saved position in the transaction.&lt;br /&gt;You can run the following script to see how savepoints work in transactions/ Stored procedures.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;drop table if exists test.savepoint_test;&lt;br /&gt;drop procedure if exists second_fail;&lt;br /&gt;drop procedure if exists prc_work;&lt;br /&gt;CREATE TABLE test.savepoint_test (&lt;br /&gt;id int not null default '0',&lt;br /&gt;name varchar(100),&lt;br /&gt;primary key (id)&lt;br /&gt;)engine=InnoDB;&lt;br /&gt;insert into test.savepoint_test values ('1', 'jack');&lt;br /&gt;insert into test.savepoint_test values ('2', 'akbar');&lt;br /&gt;select * from test.savepoint_test;&lt;br /&gt;&lt;br /&gt;start transaction;&lt;br /&gt;update test.savepoint_test set name = 'amar' where id = 1;&lt;br /&gt;select * from savepoint_test;&lt;br /&gt;&lt;br /&gt;savepoint savepoint_one;&lt;br /&gt;update savepoint_test set name = 'jill' where id = 2;&lt;br /&gt;&lt;br /&gt;select * from savepoint_test;&lt;br /&gt;rollback to savepoint_one;&lt;br /&gt;&lt;br /&gt;select * from savepoint_test;&lt;br /&gt;&lt;br /&gt;commit;&lt;br /&gt;&lt;br /&gt;select 'using savepoints in stored procedures' as message;&lt;br /&gt;&lt;br /&gt;delimiter $$&lt;br /&gt;drop procedure if exists second_fail$$&lt;br /&gt;CREATE PROCEDURE second_fail()&lt;br /&gt;BEGIN&lt;br /&gt;        INSERT  into test.savepoint_test values ('3', 'anthony');&lt;br /&gt;        INSERT  into test.savepoint_test values ('2', 'xyz');&lt;br /&gt;END;&lt;br /&gt;$$&lt;br /&gt;&lt;br /&gt;select 'ID 3 manages to get into the table but ID 2 fails due to duplicate primary key error' as message $$&lt;br /&gt;drop procedure if exists prc_work$$&lt;br /&gt;CREATE PROCEDURE prc_work()&lt;br /&gt;BEGIN&lt;br /&gt;        SAVEPOINT sp_prc_work;&lt;br /&gt;BEGIN&lt;br /&gt;        DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK TO sp_prc_work;&lt;br /&gt;        INSERT  into test.savepoint_test values ('4', 'krishna');&lt;br /&gt;        INSERT  into test.savepoint_test values ('2', 'abc');&lt;br /&gt;END;&lt;br /&gt;END;&lt;br /&gt;$$&lt;br /&gt;&lt;br /&gt;select 'ID 4 qualifies to be inserted but fails because ID 2 fails and the entire transaction is reverted to the savepoint' as message $$&lt;br /&gt;&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;start transaction;&lt;br /&gt;call second_fail();&lt;br /&gt;select * from test.savepoint_test;&lt;br /&gt;&lt;br /&gt;call prc_work();&lt;br /&gt;select * from test.savepoint_test;&lt;br /&gt;commit;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6562249656258338182?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6562249656258338182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6562249656258338182&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6562249656258338182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6562249656258338182'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2011/01/savepoints-in-transaction.html' title='Savepoints in transaction'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7381945327489338335</id><published>2010-12-21T02:10:00.000-08:00</published><updated>2010-12-21T02:13:21.406-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql case study'/><title type='text'>MySQL Case Study - 181</title><content type='html'>&lt;span style="font-weight:bold;"&gt;ON DUPLICATE KEY insert into an audit or log table&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Is there a way to accomplish this?&lt;br /&gt;&lt;br /&gt;INSERT IGNORE INTO some_table (one,two,three) VALUES(1,2,3)&lt;br /&gt;ON DUPLICATE KEY (INSERT INTO audit_table VALUES(NOW(),'Duplicate key ignored')&lt;br /&gt;&lt;br /&gt;I really don't want to use PHP for this :(&lt;br /&gt;&lt;br /&gt;http://stackoverflow.com/questions/3884344/mysql-on-duplicate-key-insert-into-an-audit-or-log-table&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;If you want to consider using a stored procedure, you can use a DECLARE CONTINUE HANDLER. Here's an example:&lt;br /&gt;&lt;br /&gt;CREATE TABLE users (&lt;br /&gt;    username    VARCHAR(30), &lt;br /&gt;    first_name  VARCHAR(30), &lt;br /&gt;    last_name   VARCHAR(30),&lt;br /&gt;    PRIMARY KEY (username)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;CREATE TABLE audit_table (timestamp datetime, description varchar(255));&lt;br /&gt;&lt;br /&gt;DELIMITER $$&lt;br /&gt;CREATE PROCEDURE add_user &lt;br /&gt;       (in_username    VARCHAR(30),&lt;br /&gt;        in_first_name  VARCHAR(30),&lt;br /&gt;        in_last_name   VARCHAR(30))&lt;br /&gt;    MODIFIES SQL DATA&lt;br /&gt;BEGIN&lt;br /&gt;    DECLARE duplicate_key INT DEFAULT 0;&lt;br /&gt;    BEGIN&lt;br /&gt;        DECLARE EXIT HANDLER FOR 1062 SET duplicate_key = 1;&lt;br /&gt;&lt;br /&gt;        INSERT INTO users (username, first_name, last_name)&lt;br /&gt;               VALUES (in_username, in_first_name, in_last_name);&lt;br /&gt;    END;&lt;br /&gt;&lt;br /&gt;    IF duplicate_key = 1 THEN&lt;br /&gt;        INSERT INTO audit_table VALUES(NOW(), 'Duplicate key ignored');&lt;br /&gt;    END IF;&lt;br /&gt;END$$&lt;br /&gt;DELIMITER ;&lt;br /&gt;&lt;br /&gt;Let's add some data, trying to insert a duplicate key:&lt;br /&gt;&lt;br /&gt;CALL add_user('userA', 'Bob', 'Smith');&lt;br /&gt;CALL add_user('userB', 'Paul', 'Green');&lt;br /&gt;CALL add_user('userA', 'Jack', 'Brown');&lt;br /&gt;&lt;br /&gt;Result:&lt;br /&gt;&lt;br /&gt;SELECT * FROM users;&lt;br /&gt;+----------+------------+-----------+&lt;br /&gt;| username | first_name | last_name |&lt;br /&gt;+----------+------------+-----------+&lt;br /&gt;| userA    | Bob        | Smith     |&lt;br /&gt;| userB    | Paul       | Green     |&lt;br /&gt;+----------+------------+-----------+&lt;br /&gt;2 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;SELECT * FROM audit_table;&lt;br /&gt;+---------------------+-----------------------+&lt;br /&gt;| timestamp           | description           |&lt;br /&gt;+---------------------+-----------------------+&lt;br /&gt;| 2010-10-07 20:17:35 | Duplicate key ignored |&lt;br /&gt;+---------------------+-----------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7381945327489338335?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7381945327489338335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7381945327489338335&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7381945327489338335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7381945327489338335'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/12/mysql-case-study-181.html' title='MySQL Case Study - 181'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3064672439067711404</id><published>2010-12-15T03:47:00.000-08:00</published><updated>2011-07-26T20:47:05.108-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Replication: step-by-step</title><content type='html'>ssh to master and slave in 2 different windows. Make sure maatkit is installed on both servers. start the script logging and mysql logging.&lt;br /&gt;&lt;br /&gt;Master: 10.10.10.56&lt;br /&gt;Slave: 10.10.10.3&lt;br /&gt;&lt;br /&gt;$$ On 10.10.10.3 (Slave)&lt;br /&gt;// check disk space&lt;br /&gt;// make sure innodb is configured but all logs are disabled in my.cnf&lt;br /&gt;// create a super user equivalent to root&lt;br /&gt;# mysql -e"grant all on *.* to 'shantanu'@'%' identified by 'shantanu@123' with grant option;"&lt;br /&gt;# mysql -e"grant all on *.* to 'shantanu'@'localhost' identified by 'shantanu@123' with grant option;"&lt;br /&gt;&lt;br /&gt;// open the port for copying the dump file from master&lt;br /&gt;# time nc -l 1234 &gt; toall_master_data.sql&lt;br /&gt;&lt;br /&gt;$$ On 10.10.10.56 (Master)&lt;br /&gt;// create a super user equivalent to root&lt;br /&gt;# mysql -e"grant all on *.* to 'shantanu'@'%' identified by 'shantanu@123' with grant option;"&lt;br /&gt;# mysql -e"grant all on *.* to 'shantanu'@'localhost' identified by 'shantanu@123' with grant option;"&lt;br /&gt;&lt;br /&gt;// copy the users and privileges to slave&lt;br /&gt;# mk-show-grants -ushantanu -pshantanu@123 | mysql -h10.10.10.3 -ushantanu -pshantanu@123&lt;br /&gt;&lt;br /&gt;// take the dump&lt;br /&gt;# time mysqldump --all-databases -R --single-transaction --master-data=2 | perl /home/shantanu/dumper.pl --delete &gt; to_all_db_to_3.sql&lt;br /&gt;real    3m21.331s&lt;br /&gt;user    1m10.234s&lt;br /&gt;sys     0m10.378s&lt;br /&gt;&lt;br /&gt;// send the dump file to slave&lt;br /&gt;# time nc 10.10.10.3 1234 &lt; to_all_db_to_3.sql &lt;br /&gt;real    1m17.768s&lt;br /&gt;user    0m1.800s&lt;br /&gt;sys     0m12.713s&lt;br /&gt;&lt;br /&gt;$$ On 10.10.10.3 (Slave)&lt;br /&gt;# time mysql &lt; to_all_db_to_3.sql &lt;br /&gt;&lt;br /&gt;~ 40 minutes&lt;br /&gt;&lt;br /&gt;// run the chnage master to command generated from the following file&lt;br /&gt;# head -100 toall_master_data.sql | grep 'CHANGE MASTER TO' | sed 's/--//' | replace ";" " , MASTER_USER='slave_user', MASTER_PASSWORD='slave_user', MASTER_HOST='10.10.10.56';"&lt;br /&gt;&lt;br /&gt;// check slave status&lt;br /&gt;mysql -e"show slave status\G"&lt;br /&gt;&lt;br /&gt;// compare row count in test database with master&lt;br /&gt;mk-table-checksum h=localhost,u=shantanu,p=shantanu@123,P=3306 --databases test h=10.10.10.56,u=shantanu,p=shantanu@123,P=3306 --databases test | mk-checksum-filter&lt;br /&gt;&lt;br /&gt;// drop user shantanu&lt;br /&gt;mysql -ushantanu -pshantanu@123 -e"drop user shantanu;"&lt;br /&gt;&lt;br /&gt;$$ On 10.10.10.56 (Master)&lt;br /&gt;// compare row count in test database with slave&lt;br /&gt;mk-table-checksum h=localhost,u=shantanu,p=shantanu@123,P=3306 --databases test h=10.10.10.3,u=shantanu,p=shantanu@123,P=3306 --databases test | mk-checksum-filter&lt;br /&gt;&lt;br /&gt;// drop user shantanu&lt;br /&gt;mysql -ushantanu -pshantanu@123 -e"drop user shantanu;"&lt;br /&gt;&lt;br /&gt;Or run the shell script to check if all the tables are in sync&lt;br /&gt;&lt;br /&gt;# time sh -xv slave_check.sh &lt;br /&gt;&lt;br /&gt;# vi slave_check.sh&lt;br /&gt;#/bin/sh&lt;br /&gt;# change the slave IP as default IP address if no IP is provided&lt;br /&gt;myslave=${1:-10.10.10.3}&lt;br /&gt;for dbName in `mysqlshow`&lt;br /&gt;do&lt;br /&gt;mk-table-checksum h=localhost,u=shantanu,p=shantanu@123,P=3306 --databases $dbName h=$myslave,u=shantanu,p=shantanu@123,P=3306 --databases $dbName --no-crc --count | mk-checksum-filter&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;This can also do done in a single command as shown below:&lt;br /&gt;&lt;br /&gt;for dbName in `mysqlshow -uroot -proot@123`; do /usr/bin/mk-table-checksum h=localhost,u=root,p=root@123,P=3306 --databases $dbName h=10.10.10.11,u=root,p=root@123,P=3306 --databases $dbName --count --no-crc | /usr/bin/mk-checksum-filter; done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3064672439067711404?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3064672439067711404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3064672439067711404&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3064672439067711404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3064672439067711404'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/12/replication-step-by-step.html' title='Replication: step-by-step'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1733981979487744639</id><published>2010-11-29T23:22:00.000-08:00</published><updated>2010-11-30T01:43:14.289-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><title type='text'>Script extract to warn user</title><content type='html'>There are times when you want to make sure that the user has verified certain parameters. Here is an extract that can be placed at the top of any script.&lt;br /&gt;&lt;br /&gt;# cat mycheck.sh&lt;br /&gt;#!/bin/sh&lt;br /&gt;# Warn and force user to check certain settings before starting the execution of script&lt;br /&gt;echo "                               &lt;br /&gt;            ********&lt;br /&gt;&lt;br /&gt;Make sure the following and continue :&lt;br /&gt;&lt;br /&gt;1. There is enough disk space available&lt;br /&gt;2. general and binary logging is disabled in my.cnf&lt;br /&gt;3. you have taken the required permissions from your boss, parents and girl friend&lt;br /&gt;&lt;br /&gt;            ********&lt;br /&gt;&lt;br /&gt;Press 'y' to continue 'n' to abort " &lt;br /&gt;    read answer&lt;br /&gt;    if [ "$answer" = "n" ] || [ "$answer" = "N" ]&lt;br /&gt;    then&lt;br /&gt;        echo "Aborting"&lt;br /&gt;        exit 160&lt;br /&gt;    fi&lt;br /&gt;&lt;br /&gt;echo "welcome and let us start the process"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1733981979487744639?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1733981979487744639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1733981979487744639&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1733981979487744639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1733981979487744639'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/script-extract-to-warn-user.html' title='Script extract to warn user'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6586046953365637643</id><published>2010-11-29T02:48:00.000-08:00</published><updated>2010-12-16T21:20:52.362-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>MySQL alert system</title><content type='html'>#!/bin/sh&lt;br /&gt;# filename myalert.sh&lt;br /&gt;# a cron that will record the mysql status to a text file every minute&lt;br /&gt;# record status of both masters&lt;br /&gt;# * * * * * mysqladmin -h111.222.333.101 -uroot -pPassWord status &gt;&gt; /home/ricie/status_success_101.txt 2&gt;&gt; /home/develop/status_err_101.txt&lt;br /&gt;# * * * * * sh -xv /home/develop/myalert.sh 101 1&gt; /home/develop/alert_succ_101.txt 2&gt; /home/develop/alert_err.txt&lt;br /&gt;&lt;br /&gt;# analyse the change in the status figures and prompt the user when MySQL is restarted, receives less than 3 queries or more than 10 slow queries&lt;br /&gt;# myalert email&lt;br /&gt;&lt;br /&gt;if [ -z "$1" ]&lt;br /&gt;then&lt;br /&gt;filename='/home/develop/status_success.txt'&lt;br /&gt;else&lt;br /&gt;filename="/home/develop/status_success_$1.txt"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;path='/home/shantanu'&lt;br /&gt;User='root'&lt;br /&gt;PassWord='root'&lt;br /&gt;mydate=`date '+%d %B %H:%M'`&lt;br /&gt;myhostname=`hostname`&lt;br /&gt;ADMIN="shantanu.oak+$myhostname@gmail.com"&lt;br /&gt;&lt;br /&gt;uptime=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -1)&lt;br /&gt;&lt;br /&gt;threads=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -2 | tail -1)&lt;br /&gt;&lt;br /&gt;questions=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -3 | tail -1)&lt;br /&gt;&lt;br /&gt;slow=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -4 | tail -1)&lt;br /&gt;&lt;br /&gt;opens=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -5 | tail -1 )&lt;br /&gt;&lt;br /&gt;flush=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -6 | tail -1 )&lt;br /&gt;&lt;br /&gt;otables=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -7 | tail -1)&lt;br /&gt;&lt;br /&gt;aqueries=$(tail -2 $filename | awk ' {&lt;br /&gt;gsub(/[a-zA-Z: ]+/," ")&lt;br /&gt;m=split($0,a," ");&lt;br /&gt;for (i=1;i&lt;=m;i++)&lt;br /&gt;if (NR==1) b[i]=a[i]; else print a[i] - b[i]&lt;br /&gt;} ' | head -8 | tail -1)&lt;br /&gt;&lt;br /&gt;echo "differnce in uptime is " $uptime&lt;br /&gt;echo "differnce in Threads are " $threads&lt;br /&gt;echo "difference in Questions are " $questions&lt;br /&gt;echo "difference in Slow queries are " $slow&lt;br /&gt;echo "difference in Opens " $opens&lt;br /&gt;echo "difference in Flush tables " $flush&lt;br /&gt;echo "difference in Open tables " $otables&lt;br /&gt;echo "difference in Queries per second " $aqueries&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if [[ $uptime -lt 0 ]];then&lt;br /&gt;&lt;br /&gt;# the message that will be written to a file, mail and SMS&lt;br /&gt;# the word space is black listed by SMS gateway&lt;br /&gt;mymessage="MySQL restarted on $1 at $mydate"&lt;br /&gt;&lt;br /&gt;# write to a file, email and SMS&lt;br /&gt;echo "$mymessage" &gt;&gt; $path/messages.txt 2&gt;&gt; $path/messages_err.txt&lt;br /&gt;echo "$mymessage" | mail -s "mysql restarted on $1" $ADMIN&lt;br /&gt;&lt;br /&gt;# sms alert add as many numbers as you want to the list&lt;br /&gt;while read mnumber&lt;br /&gt;do&lt;br /&gt;# one of the gateway not working&lt;br /&gt;# curl -Ld'username=soak&amp;password=43417010&amp;source=oksoft&amp;dmobile='$mnumber'&amp;message='"'$mymessage'"'' http://67.23.229.95/smsclient//api.php&lt;br /&gt;curl -Ld'user=shantanu.oak@gmail.com:PassWord&amp;state=4&amp;senderID=TEST SMS&amp;receipientno='$mnumber'&amp;msgtxt='"'$mymessage'"'' http://api.mVaayoo.com/mvaayooapi/MessageCompose&lt;br /&gt;done &lt;&lt; mnumber_list&lt;br /&gt;09702977470&lt;br /&gt;mnumber_list&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if [[ $questions -lt 3 ]];then&lt;br /&gt;&lt;br /&gt;# the message that will be written to a file, mail and SMS&lt;br /&gt;# the word space is black listed by SMS gateway&lt;br /&gt;mymessage="Queries $questions on $1 too few at $mydate"&lt;br /&gt;&lt;br /&gt;# write to a file, email and SMS&lt;br /&gt;echo "$mymessage" &gt;&gt; $path/messages.txt 2&gt;&gt; $path/messages_err.txt&lt;br /&gt;echo "$mymessage" | mail -s "Few questions on $1" $ADMIN&lt;br /&gt;&lt;br /&gt;# sms alert add as many numbers as you want to the list&lt;br /&gt;while read mnumber&lt;br /&gt;do&lt;br /&gt;# one of the gateway not working&lt;br /&gt;# curl -Ld'username=soak&amp;password=43417010&amp;source=oksoft&amp;dmobile='$mnumber'&amp;message='"'$mymessage'"'' http://67.23.229.95/smsclient//api.php&lt;br /&gt;#curl -Ld'user=shantanu.oak@gmail.com:PassWord&amp;state=4&amp;senderID=TEST SMS&amp;receipientno='$mnumber'&amp;msgtxt='"'$mymessage'"'' http://api.mVaayoo.com/mvaayooapi/MessageCompose&lt;br /&gt;echo "dummy text"&lt;br /&gt;done &lt;&lt; mnumber_list&lt;br /&gt;09702977470&lt;br /&gt;mnumber_list&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if [[ $slow -gt 10 ]];then&lt;br /&gt;&lt;br /&gt;# the message that will be written to a file, mail and SMS&lt;br /&gt;# the word space is black listed by SMS gateway&lt;br /&gt;mymessage="Slow queries $slow on $1 are inordinately high as on $mydate"&lt;br /&gt;&lt;br /&gt;# write to a file, email and SMS&lt;br /&gt;echo "$mymessage" &gt;&gt; $path/messages.txt 2&gt;&gt; $path/messages_err.txt&lt;br /&gt;echo "$mymessage" | mail -s "slow queries high on $1" $ADMIN&lt;br /&gt;&lt;br /&gt;# sms alert add as many numbers as you want to the list&lt;br /&gt;while read mnumber&lt;br /&gt;do&lt;br /&gt;# one of the gateway not working&lt;br /&gt;# curl -Ld'username=soak&amp;password=43417010&amp;source=oksoft&amp;dmobile='$mnumber'&amp;message='"'$mymessage'"'' http://67.23.229.95/smsclient//api.php&lt;br /&gt;#curl -Ld'user=shantanu.oak@gmail.com:PassWord&amp;state=4&amp;senderID=TEST SMS&amp;receipientno='$mnumber'&amp;msgtxt='"'$mymessage'"'' http://api.mVaayoo.com/mvaayooapi/MessageCompose&lt;br /&gt;echo "dummy text"&lt;br /&gt;done &lt;&lt; mnumber_list&lt;br /&gt;09702977470&lt;br /&gt;mnumber_list&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# count the processes and alert the user if the processes are more than 230&lt;br /&gt;myvar2=$(mysqladmin -u$User -p$PassWord processlist | wc -l | awk '{print int($1)}')&lt;br /&gt;if [[ $myvar2 -gt 230 ]];then&lt;br /&gt;mymessage="processes $myvar2 on $1 are inordinately high as on $mydate"&lt;br /&gt;&lt;br /&gt;echo "$mymessage" &gt;&gt; $path/messages.txt 2&gt;&gt; $path/messages_err.txt&lt;br /&gt;echo "$mymessage" | mail -s "slow queries high on $1" $ADMIN&lt;br /&gt;&lt;br /&gt;# sms alert add as many numbers as you want to the list&lt;br /&gt;while read mnumber&lt;br /&gt;do&lt;br /&gt;# one of the gateway not working&lt;br /&gt;# curl -Ld'username=soak&amp;password=43417010&amp;source=oksoft&amp;dmobile='$mnumber'&amp;message='"'$mymessage'"'' http://67.23.229.95/smsclient//api.php&lt;br /&gt;#curl -Ld'user=shantanu.oak@gmail.com:PassWord&amp;state=4&amp;senderID=TEST SMS&amp;receipientno='$mnumber'&amp;msgtxt='"'$mymessage'"'' http://api.mVaayoo.com/mvaayooapi/MessageCompose&lt;br /&gt;echo "dummy text"&lt;br /&gt;done &lt;&lt; mnumber_list&lt;br /&gt;09702977470&lt;br /&gt;mnumber_list&lt;br /&gt;&lt;br /&gt;fi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6586046953365637643?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6586046953365637643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6586046953365637643&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6586046953365637643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6586046953365637643'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/mysql-alert-system.html' title='MySQL alert system'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8138074597551068125</id><published>2010-11-24T04:34:00.000-08:00</published><updated>2011-04-11T04:11:29.236-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>common my.cnf file</title><content type='html'>[mysqld]&lt;br /&gt;&lt;br /&gt;# change the default datadir path and hostname used for bin and relay log&lt;br /&gt;# make sure that the binary data directory is available and has proper permissions&lt;br /&gt;# /var/lib/mysql&lt;br /&gt;# /var/log/mysql/&lt;br /&gt;# /var/run/mysqld/&lt;br /&gt;&lt;br /&gt;datadir=/var/lib/mysql/&lt;br /&gt;socket=/var/lib/mysql/mysql.sock&lt;br /&gt;user=mysql&lt;br /&gt;&lt;br /&gt;# Server ID should always be there preferably IP address&lt;br /&gt;server-id=10101067&lt;br /&gt;&lt;br /&gt;# default 8MB packet size is not enough&lt;br /&gt;max_allowed_packet=1G&lt;br /&gt;&lt;br /&gt;group_concat_max_len=500000&lt;br /&gt;ft_min_word_len=2&lt;br /&gt;&lt;br /&gt;collation_server=utf8_unicode_ci&lt;br /&gt;character_set_server=utf8&lt;br /&gt;skip-character-set-client-handshake&lt;br /&gt;&lt;br /&gt;########## Troubleshooting ##########&lt;br /&gt;&lt;br /&gt;# change to strict sql mode or use traditional more more constraints&lt;br /&gt;# sql-mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE"&lt;br /&gt;sql-mode=NO_ENGINE_SUBSTITUTION&lt;br /&gt;&lt;br /&gt;# if mysql does not start&lt;br /&gt;#user=root&lt;br /&gt;&lt;br /&gt;#to skip password&lt;br /&gt;#init_file=sql_commands.sql&lt;br /&gt;#skip-grant-tables&lt;br /&gt;#skip-networking&lt;br /&gt;&lt;br /&gt;# values 1 to 6 with varying severity&lt;br /&gt;#innodb_force_recovery=3&lt;br /&gt;&lt;br /&gt;# to avoid replication issue&lt;br /&gt;# slave_skip_errors=1062&lt;br /&gt;# lower_case_table_names=1&lt;br /&gt;&lt;br /&gt;########## Performance ##########&lt;br /&gt;&lt;br /&gt;# faster responses&lt;br /&gt;skip-name-resolve&lt;br /&gt;&lt;br /&gt;# skip-locking # deprecated&lt;br /&gt;skip-external-locking&lt;br /&gt;&lt;br /&gt;# avoid error like Lost connection to MySQL server default 5&lt;br /&gt;connect_timeout=15&lt;br /&gt;max_connect_errors=4294967295&lt;br /&gt;&lt;br /&gt;## global non engine-specific buffers&lt;br /&gt;tmp_table_size=64M&lt;br /&gt;max_heap_table_size=64M&lt;br /&gt;&lt;br /&gt;# Following parameters can be changed after running analysis&lt;br /&gt;# http://genomewiki.ucsc.edu/index.php/Tuning-primer.sh&lt;br /&gt;&lt;br /&gt;#default table cache is 64&lt;br /&gt;table_cache=1064&lt;br /&gt;# default thread cache size is 0&lt;br /&gt;thread_cache_size=16&lt;br /&gt;&lt;br /&gt;# cat /proc/sys/net/core/somaxconn&lt;br /&gt;back_log=128&lt;br /&gt;&lt;br /&gt;# default 28800 seconds&lt;br /&gt;#interactive_timeout=600&lt;br /&gt;#default wait timeout 28800&lt;br /&gt;#wait_timeout=600&lt;br /&gt;# default is 100 for max connections&lt;br /&gt;max_connections=900&lt;br /&gt;# default is 0 for max user connections that means no limit&lt;br /&gt;#max_user_connections=800&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;### per Thread buffers ###&lt;br /&gt;&lt;br /&gt;#default for sort buffer is 2M&lt;br /&gt;#sort_buffer_size=2M&lt;br /&gt;#join_buffer_size=2M&lt;br /&gt;&lt;br /&gt;#default for read buffer is .1 M&lt;br /&gt;read_buffer_size=1M&lt;br /&gt;# default for rnd buffer is .2M&lt;br /&gt;read_rnd_buffer_size=8M&lt;br /&gt;# default is 8M&lt;br /&gt;# bulk_insert_buffer_size=16M&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;########## Caching ##########&lt;br /&gt;&lt;br /&gt;## Query Cache&lt;br /&gt;# query cache between 64-128M&lt;br /&gt;query_cache_size=64M&lt;br /&gt;#query_cache_limit=1M&lt;br /&gt;#query_cache_type=1&lt;br /&gt;&lt;br /&gt;########## Logging ##########&lt;br /&gt;# General log can be enabled whenever required&lt;br /&gt;# log=/var/log/mysql/general.log&lt;br /&gt;&lt;br /&gt;# general_log=1 # for 5.1&lt;br /&gt;# general_log_file=/var/log/mysql/general.log&lt;br /&gt;# Slow query log should be enabled by default&lt;br /&gt;# slow_query_log=1 # for 5.1&lt;br /&gt;# slow_query_log_file=/var/log/mysql/slow.log&lt;br /&gt;&lt;br /&gt;# log-slow-queries=/var/log/mysql/slow-log&lt;br /&gt;long_query_time = 2&lt;br /&gt;log-queries-not-using-indexes&lt;br /&gt;&lt;br /&gt;# Error log with warnings should be enabled&lt;br /&gt;log_warnings&lt;br /&gt;log-error=/var/log/mysqld.err&lt;br /&gt;&lt;br /&gt;# Binary logs should be there for trobleshooting and replication&lt;br /&gt;# the hostname can be used as binary filename&lt;br /&gt;# make sure that partition has enough space to save binary files&lt;br /&gt;# and the directory should be available and owned by mysql&lt;br /&gt;log-bin=/var/log/mysql/hostname&lt;br /&gt;&lt;br /&gt;max_binlog_size=1024M&lt;br /&gt;expire_logs_days=12&lt;br /&gt;log_bin_trust_function_creators=TRUE&lt;br /&gt;relay-log=/var/run/mysqld/hostname-relay-bin&lt;br /&gt;# default of binlog cache is 32K&lt;br /&gt;#binlog_cache_size=4M&lt;br /&gt;&lt;br /&gt;# enabling this will make it slow but will help at the time of crash&lt;br /&gt;#sync_binlog=1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;########## MyISAM ##########&lt;br /&gt;&lt;br /&gt;## myisam&lt;br /&gt;# try du -sch /var/lib/mysql/*/*.MYI&lt;br /&gt;key_buffer_size=256M&lt;br /&gt;&lt;br /&gt;# sort, alter and repair functions uses this buffer&lt;br /&gt;myisam_sort_buffer_size=64M&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;########## InnoDB ##########&lt;br /&gt;&lt;br /&gt;default-storage-engine=InnoDB&lt;br /&gt;&lt;br /&gt;# 50-80% of RAM&lt;br /&gt;innodb_buffer_pool_size=1G&lt;br /&gt;&lt;br /&gt;# innodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextend&lt;br /&gt;innodb_log_file_size=100M&lt;br /&gt;innodb_log_buffer_size = 16M&lt;br /&gt;innodb_flush_log_at_trx_commit=2&lt;br /&gt;#innodb_lock_wait_timeout = 50&lt;br /&gt;innodb_additional_mem_pool_size=16M&lt;br /&gt;innodb_flush_method=O_DIRECT&lt;br /&gt;&lt;br /&gt;# cache tables while using file per table&lt;br /&gt;innodb_open_files=1024&lt;br /&gt;# number of cpus * number of disks * 2&lt;br /&gt;innodb_thread_concurrency=16&lt;br /&gt;&lt;br /&gt;# does not scale well with a large number of tables&lt;br /&gt;innodb_file_per_table=1&lt;br /&gt;&lt;br /&gt;########## Multi-maser replication ##########&lt;br /&gt;&lt;br /&gt;## multi-master replication setup&lt;br /&gt;#auto_increment_increment=2&lt;br /&gt;#auto_increment_offset=1&lt;br /&gt;slave_net_timeout=60&lt;br /&gt;#log_slave_updates=1&lt;br /&gt;#read_only=1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Default to using old password format for compatibility with mysql 3.x&lt;br /&gt;# clients (those using the mysqlclient10 compatibility package).&lt;br /&gt;old_passwords=1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;[mysqld_safe]&lt;br /&gt;# default 1024&lt;br /&gt;open_files_limit=4096&lt;br /&gt;log-error=/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/3043709-8138074597551068125?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8138074597551068125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8138074597551068125&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8138074597551068125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8138074597551068125'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/common-mycnf-file.html' title='common my.cnf file'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3638466546730831177</id><published>2010-11-23T21:04:00.001-08:00</published><updated>2010-11-23T21:04:35.340-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>ACID compliant engine</title><content type='html'>As all of us know that MyISAM is not ACID compliant as is InnoDB. In the following example, the first record is updated while the second one fails due to duplicate key error. This will not happen if you specify the engine as InnoDB.&lt;br /&gt;&lt;br /&gt;mysql&gt; create table test (a INT UNIQUE, b INT );&lt;br /&gt;Query OK, 0 rows affected (0.10 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into test VALUES (NULL, 2);&lt;br /&gt;Query OK, 1 row affected (0.03 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into test VALUES (NULL, 2);&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; update test set a = 1 where b = 2;&lt;br /&gt;ERROR 1062 (23000): Duplicate entry '1' for key 'a'&lt;br /&gt;mysql&gt; select * from test;&lt;br /&gt;+------+------+&lt;br /&gt;| a    | b    |&lt;br /&gt;+------+------+&lt;br /&gt;|    1 |    2 |&lt;br /&gt;| NULL |    2 |&lt;br /&gt;+------+------+&lt;br /&gt;2 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/3043709-3638466546730831177?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3638466546730831177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3638466546730831177&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3638466546730831177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3638466546730831177'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/acid-compliant-engine.html' title='ACID compliant engine'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6134608935755820974</id><published>2010-11-17T22:56:00.000-08:00</published><updated>2010-11-17T22:58:15.333-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='unix case study'/><title type='text'>Unix Case Study 26</title><content type='html'>Left outer join SQL like query from shell&lt;br /&gt;&lt;br /&gt;basically i have two files:&lt;br /&gt;&lt;br /&gt;frequency.txt: (multiple lines, space separated file containing words and a frequency)&lt;br /&gt;&lt;br /&gt;de 1711&lt;br /&gt;a 936&lt;br /&gt;et 762&lt;br /&gt;la 530&lt;br /&gt;les 482&lt;br /&gt;pour 439&lt;br /&gt;le 425&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;and i have a file containing "prohibited" words:&lt;br /&gt;&lt;br /&gt;stopwords.txt: (one single line, space separated file)&lt;br /&gt;&lt;br /&gt; au aux avec le ces dans ...&lt;br /&gt;&lt;br /&gt;so i want to delete from frequency.txt all the lines containing a word found on stopwords.txt&lt;br /&gt;&lt;br /&gt;how could i do that? i'm thinking that it could be done with awk.. something like&lt;br /&gt;&lt;br /&gt;awk 'match($0,SOMETHING_MAGICAL_HERE) == 0 {print $0}' frequency.txt &gt; new.txt&lt;br /&gt;&lt;br /&gt;but i'm not really sure... any ideas?? thxs in advance&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;http://stackoverflow.com/questions/3978626/shell-to-filter-prohibited-words-on-a-file&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6134608935755820974?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6134608935755820974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6134608935755820974&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6134608935755820974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6134608935755820974'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/unix-case-study-26.html' title='Unix Case Study 26'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-452959871156108495</id><published>2010-11-15T22:28:00.000-08:00</published><updated>2010-11-15T22:30:21.093-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Creating a filler table</title><content type='html'>If I need to create a table with a million auto generated id's then I can use the filler table as shown below.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;CREATE TABLE filler (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT) ENGINE=Memory;&lt;br /&gt;&lt;br /&gt;DELIMITER $$&lt;br /&gt;&lt;br /&gt;CREATE PROCEDURE prc_filler(cnt INT)&lt;br /&gt;BEGIN&lt;br /&gt;        DECLARE _cnt INT;&lt;br /&gt;        SET _cnt = 1;&lt;br /&gt;        WHILE _cnt &lt;= cnt DO&lt;br /&gt;                INSERT&lt;br /&gt;                INTO    filler&lt;br /&gt;                SELECT  _cnt;&lt;br /&gt;                SET _cnt = _cnt + 1;&lt;br /&gt;        END WHILE;&lt;br /&gt;END&lt;br /&gt;$$&lt;br /&gt;&lt;br /&gt;DELIMITER ;&lt;br /&gt;&lt;br /&gt;CALL prc_filler(500000);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-452959871156108495?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/452959871156108495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=452959871156108495&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/452959871156108495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/452959871156108495'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/creating-filler-table.html' title='Creating a filler table'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6087193348385305393</id><published>2010-11-15T01:07:00.000-08:00</published><updated>2010-11-15T01:09:54.145-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>MySQL strict mode</title><content type='html'>If you want mysql to care for the data-integrity then you need to add the following line to the my.cnf file.&lt;br /&gt;&lt;br /&gt;sql-mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE"&lt;br /&gt;&lt;br /&gt;NO_ENGINE_SUBSTITUTION&lt;br /&gt;If innodb engine is not available, the create table statement will throw a warning and create a MyISAM table. This mode will avoid this and throw an error instead of using default engine.&lt;br /&gt;&lt;br /&gt;STRICT_TRANS_TABLES&lt;br /&gt;Enable strict mode for InnoDB. Instead of truncating 20 characters to fit into varchar(10), it will throw an error. If you want MyISAM tables to behave the same way, use STRICT_ALL_TABLES&lt;br /&gt;&lt;br /&gt;NO_ZERO_IN_DATE&lt;br /&gt;Do not accept all zeros in the date or month field. (for example, '0000-00-00' is legal but '2010-00-01' and '2010-01-00' are not). If you do not want zero dates like 0000-00-00 then you need to use NO_ZERO_DATE&lt;br /&gt;&lt;br /&gt;The following is the default behavior of MySQL&lt;br /&gt;&lt;br /&gt;create table sqlmode(id varchar(2), birth_date date);&lt;br /&gt;insert into sqlmode values ('abc', '1970-00-16');&lt;br /&gt;insert into sqlmode values ('ab', '1970-00-16');&lt;br /&gt;insert into sqlmode values ('abc', '1970-11-16');&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from sqlmode;&lt;br /&gt;+------+------------+&lt;br /&gt;| id   | birth_date |&lt;br /&gt;+------+------------+&lt;br /&gt;| ab   | 1970-00-16 |&lt;br /&gt;| ab   | 1970-00-16 |&lt;br /&gt;| ab   | 1970-11-16 |&lt;br /&gt;+------+------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;When the sql-mode is turned on, all the above insert statements will fail. It will allow the record to enter only when the varchar and date columns are valid.&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into sqlmode values ('abc', '1970-00-16');&lt;br /&gt;ERROR 1406 (22001): Data too long for column 'id' at row 1&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into sqlmode values ('ab', '1970-00-16');&lt;br /&gt;ERROR 1292 (22007): Incorrect date value: '1970-00-16' for column 'birth_date' at row 1&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into sqlmode values ('abc', '1970-11-16');&lt;br /&gt;ERROR 1406 (22001): Data too long for column 'id' at row 1&lt;br /&gt;&lt;br /&gt;mysql&gt; insert into sqlmode values ('ab', '1970-11-16');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from sqlmode;&lt;br /&gt;+------+------------+&lt;br /&gt;| id   | birth_date |&lt;br /&gt;+------+------------+&lt;br /&gt;| ab   | 1970-11-16 | &lt;br /&gt;+------+------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6087193348385305393?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6087193348385305393/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6087193348385305393&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6087193348385305393'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6087193348385305393'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/mysql-strict-mode.html' title='MySQL strict mode'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1431385097241140720</id><published>2010-11-10T02:05:00.001-08:00</published><updated>2011-07-10T20:28:44.672-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Upgrading to 5.1 version from 5.0</title><content type='html'>1) Download Server from...&lt;br /&gt;http://mysql.com/downloads/mirror.php?id=395761&lt;br /&gt;&lt;br /&gt;MySQL-server-community-5.1.52-1.rhel5.x86_64.rpm &lt;br /&gt;&lt;br /&gt;Download client from ...&lt;br /&gt;http://mysql.com/downloads/mirror.php?id=395683&lt;br /&gt;&lt;br /&gt;MySQL-client-community-5.1.52-1.rhel5.x86_64.rpm &lt;br /&gt;&lt;br /&gt;Stop current MySQL deamon before installing the new version.&lt;br /&gt;&lt;br /&gt;2) I have to uninstall 5.0 before installing 5.1 or else I get an error as shown below:&lt;br /&gt;&lt;br /&gt;# rpm -ivh MySQL-client-community-5.1.52-1.rhel5.x86_64.rpm MySQL-server-community-5.1.52-1.rhel5.x86_64.rpm&lt;br /&gt;error: Failed dependencies:&lt;br /&gt; MySQL conflicts with mysql-5.0.77-3.el5.x86_64&lt;br /&gt; MySQL-server conflicts with mysql-server-5.0.77-3.el5.x86_64&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) While uninstalling 5.0 I was informed that the dependencies too needs to be removed.&lt;br /&gt;&lt;br /&gt;# rpm -e mysql-5.0.77-3.el5&lt;br /&gt;error: Failed dependencies:&lt;br /&gt; libmysqlclient.so.15()(64bit) is needed by (installed) perl-DBD-mysql-4.014-1.el5.rf.x86_64&lt;br /&gt; libmysqlclient.so.15(libmysqlclient_15)(64bit) is needed by (installed) perl-DBD-mysql-4.014-1.el5.rf.x86_64&lt;br /&gt; mysql is needed by (installed) perl-DBD-mysql-4.014-1.el5.rf.x86_64&lt;br /&gt;&lt;br /&gt;4) SO I remove everything that is getting in my way.&lt;br /&gt;&lt;br /&gt;# rpm -e mysql-5.0.77-3.el5 perl-DBD-mysql-4.014-1.el5.rf.x86_64 mysql-mmm-agent-2.2.1-1.el5.noarch&lt;br /&gt;&lt;br /&gt;5) And now I am all set to install the shiny new MySQL version&lt;br /&gt;&lt;br /&gt;# time rpm -ivh MySQL-client-community-5.1.52-1.rhel5.x86_64.rpm MySQL-server-community-5.1.52-1.rhel5.x86_64.rpm&lt;br /&gt;&lt;br /&gt;6) Make sure it is installed&lt;br /&gt;# rpm -qa | grep -i mysql&lt;br /&gt;MySQL-server-community-5.1.52-1.rhel5&lt;br /&gt;mysql-mmm-2.2.1-1.el5&lt;br /&gt;MySQL-client-community-5.1.52-1.rhel5&lt;br /&gt;&lt;br /&gt;7) Use the mysql_upgrade command to update the user tables. If your mysql.proc table gets corrupted due to any reason (for e.g. while trying to install 5.0 dump), use the following:&lt;br /&gt;&lt;br /&gt;mysql_upgrade -f&lt;br /&gt;&lt;br /&gt;This will forcefully fix the privilege tables. The 5.0 dump can be imported using the same -f (force) option as well. For e.g.&lt;br /&gt;&lt;br /&gt;mysql -uroot -proot@123 -f &lt; /home/today.sql&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;Installing 5.0 version of mysql is easy.&lt;br /&gt;&lt;br /&gt;# check what is installed&lt;br /&gt;# rpm -qa | grep mysql-*&lt;br /&gt;mysql-5.0.77-4.el5_4.2&lt;br /&gt;mysql-5.0.77-4.el5_4.2&lt;br /&gt;mod_auth_mysql-3.0.0-3.2.el5_3&lt;br /&gt;&lt;br /&gt;# remove any conflicting version of mysql&lt;br /&gt;# rpm -e mysql-5.0.77-4.el5_5.3.x86_64 --nodeps&lt;br /&gt;&lt;br /&gt;# install using yum&lt;br /&gt;# yum install mysql-*&lt;br /&gt;&lt;br /&gt;Setting up Install Process&lt;br /&gt;Package mysql-5.0.77-4.el5_4.2.x86_64 already installed and latest version&lt;br /&gt;Package mysql-5.0.77-4.el5_4.2.i386 already installed and latest version&lt;br /&gt;Resolving Dependencies&lt;br /&gt;--&gt; Running transaction check&lt;br /&gt;---&gt; Package mysql-bench.x86_64 0:5.0.77-4.el5_4.2 set to be updated&lt;br /&gt;=&lt;br /&gt;Install     16 Package(s)         &lt;br /&gt;Update       5 Package(s)         &lt;br /&gt;Remove       0 Package(s)         &lt;br /&gt;&lt;br /&gt;Total size: 27 M&lt;br /&gt;Is this ok [y/N]: y&lt;br /&gt;Downloading Packages:&lt;br /&gt;Running rpm_check_debug&lt;br /&gt;Running Transaction Test&lt;br /&gt;Finished Transaction Test&lt;br /&gt;Transaction Test Succeeded&lt;br /&gt;Running Transaction&lt;br /&gt;  Updating       : krb5-libs                                                                                                                                       1/26 &lt;br /&gt;  Installing     : perl-DBD-MySQL                                                                                                                                  2/26 &lt;br /&gt;  Installing     : mysql-server                                                                                                                                    3/26 &lt;br /&gt;  Updating       : libsepol                                                                                                                                        4/26 &lt;br /&gt;  Cleanup        : libsepol                                                                                                                                       24/26 &lt;br /&gt;  Cleanup        : krb5-workstation                                                                                                                               25/26 &lt;br /&gt;  Cleanup        : krb5-libs                                                                                                                                      26/26 &lt;br /&gt;&lt;br /&gt;Installed:&lt;br /&gt;  mysql-bench.x86_64 0:5.0.77-4.el5_4.2   mysql-connector-odbc.x86_64 0:3.51.26r1127-1.el5  mysql-devel.i386 0:5.0.77-4.el5_4.2  mysql-devel.x86_64 0:5.0.77-4.el5_4.2 &lt;br /&gt;  mysql-server.x86_64 0:5.0.77-4.el5_4.2  mysql-test.x86_64 0:5.0.77-4.el5_4.2             &lt;br /&gt;&lt;br /&gt;Dependency Installed:&lt;br /&gt;  e2fsprogs-devel.x86_64 0:1.39-23.el5   keyutils-libs-devel.x86_64 0:1.2-1.el5   krb5-devel.x86_64 0:1.6.1-36.el5_4.1       libselinux-devel.x86_64 0:1.33.4-5.5.el5  &lt;br /&gt;  libsepol-devel.x86_64 0:1.15.2-3.el5   libtool-ltdl.x86_64 0:1.5.22-7.el5_4     openssl-devel.x86_64 0:0.9.8e-12.el5_4.6   perl-DBD-MySQL.x86_64 0:3.0007-2.el5      &lt;br /&gt;  unixODBC.x86_64 0:2.2.11-7.1           zlib-devel.x86_64 0:1.2.3-3             &lt;br /&gt;&lt;br /&gt;Dependency Updated:&lt;br /&gt;  krb5-libs.i386 0:1.6.1-36.el5_4.1       krb5-libs.x86_64 0:1.6.1-36.el5_4.1       krb5-workstation.x86_64 0:1.6.1-36.el5_4.1       libsepol.i386 0:1.15.2-3.el5      &lt;br /&gt;  libsepol.x86_64 0:1.15.2-3.el5         &lt;br /&gt;&lt;br /&gt;Complete!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# start mysql&lt;br /&gt;# /etc/init.d/mysqld start&lt;br /&gt;Initializing MySQL database:  Installing MySQL system tables...&lt;br /&gt;OK&lt;br /&gt;Filling help tables...&lt;br /&gt;OK&lt;br /&gt;&lt;br /&gt;To start mysqld at boot time you have to copy&lt;br /&gt;support-files/mysql.server 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;To do so, start the server, then issue the following commands:&lt;br /&gt;/usr/bin/mysqladmin -u root password 'new-password'&lt;br /&gt;/usr/bin/mysqladmin -u root -h vishnuvm7.hyd.wc password 'new-password'&lt;br /&gt;&lt;br /&gt;Alternatively you can run:&lt;br /&gt;/usr/bin/mysql_secure_installation&lt;br /&gt;&lt;br /&gt;which will also give you the option of removing the test&lt;br /&gt;databases and anonymous user created by default.  This is&lt;br /&gt;strongly recommended for production servers.&lt;br /&gt;&lt;br /&gt;See the manual for more instructions.&lt;br /&gt;&lt;br /&gt;You can start the MySQL daemon with:&lt;br /&gt;cd /usr ; /usr/bin/mysqld_safe &amp;&lt;br /&gt;&lt;br /&gt;You can test the MySQL daemon with mysql-test-run.pl&lt;br /&gt;cd mysql-test ; perl mysql-test-run.pl&lt;br /&gt;&lt;br /&gt;Please report any problems with the /usr/bin/mysqlbug script!&lt;br /&gt;&lt;br /&gt;The latest information about MySQL is available on the web at&lt;br /&gt;http://www.mysql.com&lt;br /&gt;Support MySQL by buying support/licenses at http://shop.mysql.com&lt;br /&gt;[  OK  ]&lt;br /&gt;Starting MySQL:  [  OK  ]&lt;br /&gt;[root@vishnuvm7 shantanu]# mysql&lt;br /&gt;Welcome to the MySQL monitor.  Commands end with ; or \g.&lt;br /&gt;Your MySQL connection id is 2&lt;br /&gt;Server version: 5.0.77 Source distribution&lt;br /&gt;&lt;br /&gt;Type 'help;' or '\h' for help. Type '\c' to clear the buffer.&lt;br /&gt;&lt;br /&gt;mysql&gt; show databases;&lt;br /&gt;+--------------------+&lt;br /&gt;| Database           |&lt;br /&gt;+--------------------+&lt;br /&gt;| information_schema | &lt;br /&gt;| mysql              | &lt;br /&gt;| test               | &lt;br /&gt;+--------------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# rpm -qa | grep -i mysql-*&lt;br /&gt;mysql-5.0.77-4.el5_4.2&lt;br /&gt;mysql-server-5.0.77-4.el5_4.2&lt;br /&gt;mysql-test-5.0.77-4.el5_4.2&lt;br /&gt;mysql-bench-5.0.77-4.el5_4.2&lt;br /&gt;mysql-5.0.77-4.el5_4.2&lt;br /&gt;perl-DBD-MySQL-3.0007-2.el5&lt;br /&gt;mod_auth_mysql-3.0.0-3.2.el5_3&lt;br /&gt;mysql-connector-odbc-3.51.26r1127-1.el5&lt;br /&gt;mysql-devel-5.0.77-4.el5_4.2&lt;br /&gt;mysql-devel-5.0.77-4.el5_4.2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1431385097241140720?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1431385097241140720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1431385097241140720&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1431385097241140720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1431385097241140720'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/upgrading-to-51-version-from-50.html' title='Upgrading to 5.1 version from 5.0'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-432543382960997555</id><published>2010-11-08T02:50:00.000-08:00</published><updated>2010-11-08T02:52:02.727-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Full text search</title><content type='html'>MySQL's full text search is not the only option to search for a word anywhere in the table. For e.g. I have a table called tblName in the database "DbName" and I want to search for a word "denmyr". &lt;br /&gt;I am not sure about which column to search for. I can use the following shell script to generate XML file of the records those contain the word.&lt;br /&gt;&lt;br /&gt;# vi fulltext.sh&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;mydata=`mysqldump DbName tblName --skip-extended-insert | grep -i 'denmyr' | awk '{print $5}' | awk -F',' '{print $1}' | replace '('  ''`&lt;br /&gt;for record in $mydata&lt;br /&gt;do&lt;br /&gt;mysql DbName -Xe"select * from tblName where ofac_key=$record"&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-432543382960997555?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/432543382960997555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=432543382960997555&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/432543382960997555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/432543382960997555'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/full-text-search.html' title='Full text search'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7278593382301480348</id><published>2010-11-01T23:35:00.000-07:00</published><updated>2010-11-01T23:51:22.269-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Logging status of MMM</title><content type='html'>You can check the Multi Master status and log it to a text file whenever an issue is detected.&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;qsec=`/usr/sbin/mmm_control show | grep ONLINE | grep -v "^$" | wc -l`&lt;br /&gt;SEC=0&lt;br /&gt;if [ $qsec -eq $SEC ]; then&lt;br /&gt;&lt;br /&gt;curl -Ld"user=shantanu.oak@gmail.com:password&amp;senderID=TEST SMS&amp;receipientno=9702977470&amp;msgtxt=problem with MMM detected as on `date`&amp;state=4" http://api.mVaayoo.com/mvaayooapi/MessageCompose&lt;br /&gt;&lt;br /&gt;echo "problem with MMM detected as on `date`" &gt;&gt; /home/shantanu/mmstatus.txt&lt;br /&gt;/usr/sbin/mmm_control show &gt;&gt; /home/shantanu/mmstatus.txt&lt;br /&gt;&lt;br /&gt;fi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7278593382301480348?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7278593382301480348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7278593382301480348&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7278593382301480348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7278593382301480348'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/logging-status-of-mmm.html' title='Logging status of MMM'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-119385677001884786</id><published>2010-11-01T21:49:00.001-07:00</published><updated>2011-01-19T20:56:55.344-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql FAQ'/><title type='text'>Master - Maser Replication Manager</title><content type='html'>MMM (Master-Master Replication Manager) is a set of flexible scripts to perform monitoring/failover and management of MySQL Master-Master replication configurations (with only one node writable at any time). The toolset also has the ability to read balance standard master/slave configurations with any number of slaves, so you can use it to move virtual IP addresses around a group of servers depending on whether they are behind in replication. &lt;br /&gt;&lt;br /&gt;The main functionality is provided through the following three scripts:&lt;br /&gt;&lt;br /&gt;mmm_mond: monitoring daemon which does all monitoring work and makes all decisions about roles moving and so on. &lt;br /&gt;mmm_agentd: agent daemon which runs on each MySQL server and provides monitoring node with simple set of remote services. &lt;br /&gt;mmm_control: simple script dedicated to management of the mmm_mond processes by commands. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# start and stop MMM Monitor&lt;br /&gt;/etc/init.d/mysql-mmm-monitor start&lt;br /&gt;/etc/init.d/mysql-mmm-monitor status&lt;br /&gt;/etc/init.d/mysql-mmm-monitor stop&lt;br /&gt;&lt;br /&gt;# Show MMM details&lt;br /&gt;/usr/sbin/mmm_control show&lt;br /&gt;/usr/sbin/mmm_control show | grep -v 'ONLINE'&lt;br /&gt;/usr/sbin/useradd --comment "MMM Script owner" --shell /sbin/nologin mmmd&lt;br /&gt;&lt;br /&gt;# Config files&lt;br /&gt;vi /etc/default/mysql-mmm-monitor&lt;br /&gt;vi /etc/mysql-mmm/mmm_common.conf&lt;br /&gt;vi /etc/mysql-mmm/mmm_mon.conf&lt;br /&gt;&lt;br /&gt;A typical MMM setup looks like this...&lt;br /&gt;/usr/sbin/mmm_control show&lt;br /&gt;  db1(192.168.100.101) master/ONLINE. Roles: reader(192.168.100.122)&lt;br /&gt;  db2(192.168.100.102) master/ONLINE. Roles: reader(192.168.100.121), writer(192.168.100.123)&lt;br /&gt;&lt;br /&gt;And in order to check the logs on monitor and DB servers you can use the command...&lt;br /&gt;tail /var/log/mysql-mmm/mmm_mond.log&lt;br /&gt;tail /var/log/mysql-mmm/mmm_agentd.log&lt;br /&gt;&lt;br /&gt;Here are the permissions those need to be created in order to monitor the replication.&lt;br /&gt;&lt;br /&gt;GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'%' IDENTIFIED BY 'monitor_password';&lt;br /&gt;GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'%' IDENTIFIED BY 'agent_password';&lt;br /&gt;&lt;br /&gt;GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%' IDENTIFIED BY 'replication_password';&lt;br /&gt;&lt;br /&gt;grant replication slave on *.* to 'slave_user'@'%' IDENTIFIED BY 'slave_user';&lt;br /&gt;# One of the last 2 statements can be used&lt;br /&gt;&lt;br /&gt;And do not forget to check if the following setting is there in my.cnf file&lt;br /&gt;log_slave_updates   = 1&lt;br /&gt;&lt;br /&gt;More info can be found here...&lt;br /&gt;http://mysql-mmm.org/mmm2:guide&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-119385677001884786?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/119385677001884786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=119385677001884786&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/119385677001884786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/119385677001884786'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/master-maser-replication-manager.html' title='Master - Maser Replication Manager'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4126816945914863074</id><published>2010-11-01T03:33:00.000-07:00</published><updated>2010-11-01T03:34:26.554-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql case study'/><title type='text'>MySQL Case Study - 180</title><content type='html'>Finding records in a given date range&lt;br /&gt;&lt;br /&gt;I'm very new to MySQL and I'm trying to query between 4 specific times each day;&lt;br /&gt;&lt;br /&gt;1. Where &gt;= PREVIOUS DAY 15:00:00 and &lt; TODAY 11:00:00&lt;br /&gt;OR&lt;br /&gt;2. Where &gt;= TODAY 11:00:00 and &lt; TODAY 15:00:00&lt;br /&gt;&lt;br /&gt;Is it even possible to use the NOW() plus a specific time? This would query each day. If anyone can helps, that would be great!&lt;br /&gt;&lt;br /&gt;http://forums.mysql.com/read.php?22,388833,388833#msg-388833&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4126816945914863074?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4126816945914863074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4126816945914863074&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4126816945914863074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4126816945914863074'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/mysql-case-study-180.html' title='MySQL Case Study - 180'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3846638884101310444</id><published>2010-11-01T02:36:00.000-07:00</published><updated>2010-11-01T02:37:25.433-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>MySQL Data Directory</title><content type='html'>MySQL Data directory should have it's own partition. The main adtantage is that you can simplify the backup process. So assuming that the sda and sdb both have equal size, we can copy the data from one partition to another.&lt;br /&gt;&lt;br /&gt;Backup Entire Harddisk&lt;br /&gt;To backup an entire copy of a hard disk to another hard disk. &lt;br /&gt;Device name of the source hard disk is /dev/hda, and device name of the target hard disk is /dev/hdb.&lt;br /&gt;# dd if=/dev/sda of=/dev/sdb&lt;br /&gt;&lt;br /&gt;* “if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.&lt;br /&gt;* If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.&lt;br /&gt;* Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.&lt;br /&gt;&lt;br /&gt;In the copy of hard drive to hard drive using dd command given below, sync option allows you to copy everything using synchronized I/O.&lt;br /&gt;# dd if=/dev/sda of=/dev/sdb conv=noerror,sync&lt;br /&gt;&lt;br /&gt;Create an Image of a Hard Disk&lt;br /&gt;# dd if=/dev/hda of=~/hdadisk.img&lt;br /&gt;&lt;br /&gt;Restore using Hard Disk Image&lt;br /&gt;# dd if=hdadisk.img of=/dev/hdb&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3846638884101310444?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3846638884101310444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3846638884101310444&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3846638884101310444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3846638884101310444'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/mysql-data-directory.html' title='MySQL Data Directory'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5649701088203113050</id><published>2010-11-01T00:22:00.000-07:00</published><updated>2010-11-01T00:25:33.381-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Aspersa tools</title><content type='html'>The Aspersa tool does tell you almost everything that I need to know about MySQL variables.&lt;br /&gt;&lt;br /&gt;http://aspersa.googlecode.com/svn/html/mysql-summary.html&lt;br /&gt;&lt;br /&gt;It seems to be one of the most important tool any DBA will like to have in his toolbox.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5649701088203113050?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5649701088203113050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5649701088203113050&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5649701088203113050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5649701088203113050'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/11/aspersa-tools.html' title='Aspersa tools'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3903431625021438287</id><published>2010-10-27T05:32:00.001-07:00</published><updated>2010-10-27T05:38:08.310-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql case study'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>MySQL Case Study - 179</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Efficient full-text searchs on large sets of data&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the answer to the question posted by one of the Experts on this blog.&lt;br /&gt;&lt;br /&gt;http://community.livejournal.com/mysql/138390.html&lt;br /&gt;&lt;br /&gt;If you want to search for a word in a given table, the best option is to use the 'Full Text Search' that is available only for the MyISAM tables.&lt;br /&gt;As you can see from the following statements, I can search for the word "sham" without using Full Text indexes.&lt;br /&gt;You will have to add the Stored procedure available here...&lt;br /&gt;&lt;br /&gt;http://forge.mysql.com/tools/tool.php?id=204&lt;br /&gt;&lt;br /&gt;The only statement that needs explanation is the call for the stored procedure. Here is how to use the procedure to explode almost any table to your advantage.&lt;br /&gt;&lt;br /&gt;CALL mysql.normalize_table('test.Employee', 'id', 'Name', ' ');&lt;br /&gt;&lt;br /&gt;"mysql" can be replaced with the DB Name where the procedure is stored. &lt;br /&gt;"normalize_table" is the name of the procedure that you can download from URL mentioned above.&lt;br /&gt;"test.Employee" is the table to be split. &lt;br /&gt;"id" is the Unique key of that table (usually auto incremented primary key)&lt;br /&gt;"Name" is the column name that needs to be exploded. &lt;br /&gt;Space ' ' is the delimiter.&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt;drop table if exists mysql.SplitValues;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;CREATE TABLE mysql.SplitValues (cid varchar(40), value varchar(500) ) ENGINE=MyISAM;&lt;br /&gt;Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;drop table if exists test.Employee;&lt;br /&gt;Query OK, 0 rows affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;CREATE TABLE test.Employee (&lt;br /&gt;`id` int(11) default NULL,&lt;br /&gt;`Name` varchar(50) NOT NULL,&lt;br /&gt;`PhoneNo` varchar(15) default 'Unknown Phone',&lt;br /&gt;PRIMARY KEY  (`id`)&lt;br /&gt;);&lt;br /&gt;Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;INSERT INTO test.Employee VALUES (1, 'Manohar Ram','12345');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;INSERT INTO test.Employee VALUES (2, 'Manohar1 sham','12345');&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;select * from test.Employee;&lt;br /&gt;+----+---------------+---------+&lt;br /&gt;| id | Name          | PhoneNo |&lt;br /&gt;+----+---------------+---------+&lt;br /&gt;|  1 | Manohar Ram   | 12345   |&lt;br /&gt;|  2 | Manohar1 sham | 12345   |&lt;br /&gt;+----+---------------+---------+&lt;br /&gt;2 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;CALL mysql.normalize_table('test.Employee', 'id', 'Name', ' ');&lt;br /&gt;Query OK, 0 rows affected, 1 warning (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;select * from mysql.SplitValues;&lt;br /&gt;+------+----------+---------------------+&lt;br /&gt;| cid  | value    | dateadded           |&lt;br /&gt;+------+----------+---------------------+&lt;br /&gt;| 1    | Manohar  | 2010-10-27 08:18:56 |&lt;br /&gt;| 1    | Ram      | 2010-10-27 08:18:56 |&lt;br /&gt;| 2    | Manohar1 | 2010-10-27 08:18:56 |&lt;br /&gt;| 2    | sham     | 2010-10-27 08:18:56 |&lt;br /&gt;+------+----------+---------------------+&lt;br /&gt;4 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;alter table SplitValues add key (value, cid);&lt;br /&gt;Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;Records: 0  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;mysql&gt;select a.* from test.Employee as a inner join mysql.SplitValues as b on a.id = b.cid where b.value = 'sham';&lt;br /&gt;+----+---------------+---------+&lt;br /&gt;| id | Name          | PhoneNo |&lt;br /&gt;+----+---------------+---------+&lt;br /&gt;|  2 | Manohar1 sham | 12345   |&lt;br /&gt;+----+---------------+---------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;(08:22) mysql&gt;explain select a.* from test.Employee as a inner join mysql.SplitValues as b on a.id = b.cid where b.value = 'sham';&lt;br /&gt;+----+-------------+-------+--------+---------------+---------+---------+-------------+------+--------------------------+&lt;br /&gt;| id | select_type | table | type   | possible_keys | key     | key_len | ref         | rows | Extra                    |&lt;br /&gt;+----+-------------+-------+--------+---------------+---------+---------+-------------+------+--------------------------+&lt;br /&gt;|  1 | SIMPLE      | b     | ref    | value         | value   | 503     | const       |    1 | Using where; Using index |&lt;br /&gt;|  1 | SIMPLE      | a     | eq_ref | PRIMARY       | PRIMARY | 4       | mysql.b.cid |    1 | Using where              |&lt;br /&gt;+----+-------------+-------+--------+---------------+---------+---------+-------------+------+--------------------------+&lt;br /&gt;2 rows in set (0.01 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3903431625021438287?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3903431625021438287/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3903431625021438287&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3903431625021438287'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3903431625021438287'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/10/mysql-case-study-179.html' title='MySQL Case Study - 179'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6490681179314472407</id><published>2010-10-26T02:45:00.000-07:00</published><updated>2010-10-26T02:52:07.494-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql FAQ'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Understanding Foreign Keys</title><content type='html'>1) Foreign keys are used to restrict the data being inserted unless the parent record is created. Isn't it logical that the child can not be born unless the parents are born? Therefore when I try to create the child table first, I get an error 1005 - (Can't create table).&lt;br /&gt;2) While I am inserting the records, I have to follow the same sequence. &lt;br /&gt;Therefore the first insert into child table fails with error no 1452 - (Cannot add or update a child row: a foreign key constraint fails) since no corresponding record is present in the parent table. Once I insert a record in parent table, my child table will allow it as well.&lt;br /&gt;3) When I am trying to drop both the tables, I need to drop the child first and then the parent. Or else I get an error 1217 - (Cannot delete or update a parent row)&lt;br /&gt;&lt;br /&gt;# Remember, the child has to reference a column to parent and not the other way round.&lt;br /&gt;&lt;br /&gt;create table child(&lt;br /&gt;userID int not null,&lt;br /&gt;FOREIGN KEY (userID) REFERENCES parent(ID),&lt;br /&gt;primary key (userID)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;ERROR 1005 (HY000): Can't create table './test/child.frm' (errno: 150)&lt;br /&gt;&lt;br /&gt;CREATE TABLE parent(&lt;br /&gt;  `ID` int(11) default NULL,&lt;br /&gt;  `name` varchar(100) default NULL,&lt;br /&gt;  `city` varchar(100) default NULL,&lt;br /&gt;key (ID)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;create table child(&lt;br /&gt;userID int not null,&lt;br /&gt;FOREIGN KEY (userID) REFERENCES parent(ID),&lt;br /&gt;primary key (userID)&lt;br /&gt;) ENGINE=InnoDB;&lt;br /&gt;&lt;br /&gt;insert into child values (1);&lt;br /&gt;ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test/child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`userID`) REFERENCES `parent` (`ID`));&lt;br /&gt;&lt;br /&gt;insert into parent values (1, 'abc', 'delhi');&lt;br /&gt;insert into child values (1);&lt;br /&gt;&lt;br /&gt;drop table if exists parent;&lt;br /&gt;ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails;&lt;br /&gt;&lt;br /&gt;drop table if exists child;&lt;br /&gt;drop table if exists parent;&lt;br /&gt;&lt;br /&gt;The same table can be a parent and a child. It's like a family tree. The grandpa has 2 sons and each son will have 1 or 2 children.&lt;br /&gt;&lt;br /&gt;http://dev.mysql.com/downloads/workbench/&lt;br /&gt;&lt;br /&gt;If you are using mysql workbench, you can easily create a graphical representation of the data structure. On the "Database" menu, there is a "Reverse Engineer" wizard. It will let you connect to a MySQL server and reverse engineer schema. The graph generated will show the "References:" and "Referenced By:" columns. "References" will show the parents of the current table and "Referenced By" will show its children. Parents are shown in green dotted line with the sing of "&gt;". The child tables are linked with blue line.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6490681179314472407?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6490681179314472407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6490681179314472407&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6490681179314472407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6490681179314472407'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/10/understanding-foreign-keys.html' title='Understanding Foreign Keys'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4630347444972356451</id><published>2010-09-02T04:20:00.000-07:00</published><updated>2010-09-02T04:21:12.732-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Dates as text?</title><content type='html'>Saving dates in text column is a bad idea. But if we already have data entered into the column, how to correct it?&lt;br /&gt;In the following example, I have stored all the values in mm/dd/YYYY format and want to change it to the standard mysql date format.&lt;br /&gt;&lt;br /&gt;mysql&gt;create table datevar(mydate varchar(20));&lt;br /&gt;Query OK, 0 rows affected (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;insert into datevar values ('12/31/2009'), ('3/23/2010'), ('09/14/1999');&lt;br /&gt;Query OK, 3 rows affected (0.00 sec)&lt;br /&gt;Records: 3  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;mysql&gt;select * from datevar;&lt;br /&gt;+------------+&lt;br /&gt;| mydate     |&lt;br /&gt;+------------+&lt;br /&gt;| 12/31/2009 |&lt;br /&gt;| 3/23/2010  |&lt;br /&gt;| 09/14/1999 |&lt;br /&gt;+------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;update datevar set mydate = str_to_date(mydate, '%m/%d/%Y');&lt;br /&gt;Query OK, 3 rows affected (0.00 sec)&lt;br /&gt;Rows matched: 3  Changed: 3  Warnings: 0&lt;br /&gt;&lt;br /&gt;mysql&gt;select * from datevar;&lt;br /&gt;+------------+&lt;br /&gt;| mydate     |&lt;br /&gt;+------------+&lt;br /&gt;| 2009-12-31 |&lt;br /&gt;| 2010-03-23 |&lt;br /&gt;| 1999-09-14 |&lt;br /&gt;+------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;alter table datevar modify mydate date;&lt;br /&gt;Query OK, 3 rows affected (0.01 sec)&lt;br /&gt;Records: 3  Duplicates: 0  Warnings: 0&lt;br /&gt;&lt;br /&gt;mysql&gt;show create table datevar\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: datevar&lt;br /&gt;Create Table: CREATE TABLE `datevar` (&lt;br /&gt;  `mydate` date default NULL&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.01 sec)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4630347444972356451?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4630347444972356451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4630347444972356451&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4630347444972356451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4630347444972356451'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/09/dates-as-text.html' title='Dates as text?'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8111454556317263942</id><published>2010-08-31T00:13:00.000-07:00</published><updated>2010-08-31T00:15:49.391-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql case study'/><title type='text'>MySQL Case Study - 178</title><content type='html'>&lt;span style="font-weight:bold;"&gt;substring to return all values after delimiter&lt;/span&gt;&lt;br /&gt;How do I get all the values after the first delimiter? In the following example I am expecting '&lt;span style="font-style:italic;"&gt;xyz@yahoo.com,pqr@company.com&lt;/span&gt;'&lt;br /&gt;&lt;br /&gt;(02:40) mysql&gt;select substring_index('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',',  1) as first;&lt;br /&gt;+-----------------+&lt;br /&gt;| first           |&lt;br /&gt;+-----------------+&lt;br /&gt;| abc@hotmail.com |&lt;br /&gt;+-----------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;(02:41) mysql&gt;select substring_index('abc@hotmail.com,xyz@yahoo.com,pqr@company.com', ',',  -1) as last;&lt;br /&gt;+-----------------+&lt;br /&gt;| last            |&lt;br /&gt;+-----------------+&lt;br /&gt;| pqr@company.com |&lt;br /&gt;+-----------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;http://stackoverflow.com/questions/3606623/substring-to-return-all-values-after-delimiter&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8111454556317263942?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8111454556317263942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8111454556317263942&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8111454556317263942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8111454556317263942'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/mysql-case-study-178.html' title='MySQL Case Study - 178'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6800636093898204699</id><published>2010-08-25T02:01:00.000-07:00</published><updated>2010-08-25T02:02:53.280-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Using different location for Data</title><content type='html'>You can specify the path of the data directory while creating a table. For e.g.&lt;br /&gt;&lt;br /&gt;create table mytest (id int, name varchar(100))&lt;br /&gt;ENGINE = MyISAM&lt;br /&gt;COMMENT = 'data directory is var mylink configured by shantanu'&lt;br /&gt;DATA DIRECTORY = '/var/mylink';&lt;br /&gt;&lt;br /&gt;I have added the comment so that others will know about my expertise. The index file .MYI can also be saved in the same location using the following parameter.&lt;br /&gt;INDEX DIRECTORY = '/var/mylink';&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;If you have already created the table, you will have to manually move the file to the new location and crate a symbolic link.&lt;br /&gt;&lt;br /&gt;1) Check if symbolic links are supported.&lt;br /&gt;mysql&gt;SHOW VARIABLES LIKE 'have_symlink';&lt;br /&gt;+---------------+-------+&lt;br /&gt;| Variable_name | Value |&lt;br /&gt;+---------------+-------+&lt;br /&gt;| have_symlink  | YES   |&lt;br /&gt;+---------------+-------+&lt;br /&gt;1 row in set (0.06 sec)&lt;br /&gt;&lt;br /&gt;2) Lock the table so that no writes are possible.&lt;br /&gt;mysql&gt;flush tables with read lock;&lt;br /&gt;&lt;br /&gt;3) Create a directory on the partition where there is enough space. For e.g. /var/&lt;br /&gt;mkdir /var/mylink&lt;br /&gt;&lt;br /&gt;4) Change the permission to 777 or 770&lt;br /&gt;chown mysql:mysql /var/mylink&lt;br /&gt;chmod 770 /var/mylink&lt;br /&gt;&lt;br /&gt;5) Move the big data file to the new location&lt;br /&gt;mv /mysql-data/shantanu/contact_attach.MYD /var/mylink/contact_attach.MYD&lt;br /&gt;&lt;br /&gt;6) Symbolically link it&lt;br /&gt;ln -sf /var/mylink/contact_attach.MYD /mysql-data/shantanu/contact_attach.MYD&lt;br /&gt;&lt;br /&gt;7) Unlock tables&lt;br /&gt;mysql&gt; unlock tables;&lt;br /&gt;&lt;br /&gt;8) flush tables so that mysql will reread table.&lt;br /&gt;mysql&gt;flush tables shantanu.contact_attach;&lt;br /&gt;&lt;br /&gt;Repair the table if necessary. &lt;br /&gt;&lt;br /&gt;When I issue the repair table command, a tempoarary file (.MYD) is created in the new location and not in the data-directory.&lt;br /&gt;# ls -lht&lt;br /&gt;total 3.0G&lt;br /&gt;-rw-rw---- 1 mysql mysql 1.3G Aug 24 01:07 contact_attach.TMD&lt;br /&gt;-rw-rw---- 1 mysql mysql 1.7G Aug 24 00:55 contact_attach.MYD&lt;br /&gt;&lt;br /&gt;Note: The read lock will be global. It is necessary while we move the file to the new location. The expected downtime will be less than one minute per GB. You can move the file without the lock if you are sure that the company is not in use at that time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6800636093898204699?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6800636093898204699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6800636093898204699&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6800636093898204699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6800636093898204699'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/using-different-location-for-data.html' title='Using different location for Data'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4802986255164512124</id><published>2010-08-21T03:40:00.000-07:00</published><updated>2011-06-19T19:48:10.173-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>3 reasons to avoid timestamp</title><content type='html'>Here are 3 reasons why you should avoid "timestamp" column type.&lt;br /&gt;&lt;br /&gt;1) Range: It can store values only from 1st Jan 1970 to 31 Dec 2037. This range is not enough for most applications.&lt;br /&gt;&lt;br /&gt;2) On update clause:&lt;br /&gt;As you can see from the following screen, I specified only a "timestamp" column type in the create table statement. MySQL silently added the "on update CURRENT_TIMESTAMP". When I tried to update a column, the value of "mytime" column was changed as well from 02 to 33 (seconds). This is unexpected behavior for a novice coder.&lt;br /&gt;&lt;br /&gt;mysql&gt;use test;&lt;br /&gt;mysql&gt;create table stamptest(id int, name varchar(100), mytime timestamp);&lt;br /&gt;Query OK, 0 rows affected (0.03 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;show create table stamptest\G&lt;br /&gt;*************************** 1. row ***************************&lt;br /&gt;       Table: stamptest&lt;br /&gt;Create Table: CREATE TABLE `stamptest` (&lt;br /&gt;  `id` int(11) default NULL,&lt;br /&gt;  `name` varchar(100) default NULL,&lt;br /&gt;  `mytime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1&lt;br /&gt;1 row in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;insert into stamptest values (1, 'john', NULL);&lt;br /&gt;Query OK, 1 row affected (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;select * from stamptest;&lt;br /&gt;+------+------+---------------------+&lt;br /&gt;| id   | name | mytime              |&lt;br /&gt;+------+------+---------------------+&lt;br /&gt;|    1 | john | 2010-08-21 06:21:02 | &lt;br /&gt;+------+------+---------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt;update stamptest set name = 'abcd' where id = 1;&lt;br /&gt;Query OK, 1 row affected (0.00 sec)&lt;br /&gt;Rows matched: 1  Changed: 1  Warnings: 0&lt;br /&gt;&lt;br /&gt;(06:21) mysql&gt;select * from stamptest;&lt;br /&gt;+------+------+---------------------+&lt;br /&gt;| id   | name | mytime              |&lt;br /&gt;+------+------+---------------------+&lt;br /&gt;|    1 | abcd | 2010-08-21 06:21:33 | &lt;br /&gt;+------+------+---------------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) Back-up using dump&lt;br /&gt;The time saved in the timestamp column will get adjusted to the timezone of the server from where you are trying to run the mysqldump command.&lt;br /&gt;The --skip-tz-utc switch needs to be added to the dump command and most people are unaware of this.&lt;br /&gt;&lt;br /&gt;http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_tz-utc&lt;br /&gt;&lt;br /&gt;The only advantage that I can see is that it consumes 4 bytes compared to datetime's 8 bytes. This does not make much difference to most general purpose applications.&lt;br /&gt;&lt;br /&gt;The poor PHP programmers have their own deadlines and are less interested in learning these things. Do not use "timestamp" column type and avoid using from_unixtime() and unix_timestamp() functions to save datetime at any cost. The only option left to save the date+time is... what else? "datetime"!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4802986255164512124?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4802986255164512124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4802986255164512124&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4802986255164512124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4802986255164512124'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/3-reasons-to-avoid-timestamp.html' title='3 reasons to avoid timestamp'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1827862505748531865</id><published>2010-08-20T23:02:00.001-07:00</published><updated>2010-08-20T23:49:37.377-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Information Schema Tables</title><content type='html'>When the database has too many tables or when the innodb table space is too large, you can not run queries against information_Schema Database. It is a good idea to copy the data of those tables to a new database, for e.g. "schemaBackup". Here is the script that will do the needful.&lt;br /&gt;&lt;br /&gt;# cat stats.sh &lt;br /&gt;#!/bin/sh&lt;br /&gt;mysql -e"create database if not exists schemaBackup";&lt;br /&gt;&lt;br /&gt;for tblName in `mysql -e"show tables from information_schema"`&lt;br /&gt;do&lt;br /&gt;mysql -e"drop table if exists schemaBackup.$tblName;"&lt;br /&gt;mysql -e"create table schemaBackup.$tblName select * from information_schema.$tblName;"&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;for tblName in `mysql -e"show tables from mysql"`&lt;br /&gt;do&lt;br /&gt;mysql -e"drop table if exists schemaBackup.$tblName;"&lt;br /&gt;mysql -e"create table schemaBackup.$tblName select * from mysql.$tblName;"&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1827862505748531865?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1827862505748531865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1827862505748531865&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1827862505748531865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1827862505748531865'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/information-schema-tables.html' title='Information Schema Tables'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1198368836367832042</id><published>2010-08-19T23:14:00.000-07:00</published><updated>2010-08-19T23:15:22.132-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Backup using mylvmbackup</title><content type='html'>Here are the commands to create a mylvmbackup user with minimal privileges:&lt;br /&gt;&lt;br /&gt;    CREATE USER 'mylvmbackup'@'localhost' IDENTIFIED BY '12345';&lt;br /&gt;    GRANT RELOAD, REPLICATION CLIENT ON *.* TO 'mylvmbackup'@'localhost';&lt;br /&gt;    GRANT SELECT ON mysql.* TO 'mylvmbackup'@'localhost';&lt;br /&gt;&lt;br /&gt;In the mylvmbackup.conf file, the correlating rows are:&lt;br /&gt;&lt;br /&gt;    [mysql]&lt;br /&gt;    user=mylvmbackup&lt;br /&gt;    password=12345&lt;br /&gt;    host=localhost&lt;br /&gt;&lt;br /&gt;By default, mylvmbackup creates a .tar.gz compressed backup file of your data.&lt;br /&gt;&lt;br /&gt;mylvmbackup supports backing up the uncompressed files using rsync. To copy MySQL data to a remote host, configure the following in the mylvmbackup.conf file:&lt;br /&gt;    [fs]&lt;br /&gt;    backupdir=root@backuphost:/data/backup/mysql&lt;br /&gt;    [misc]&lt;br /&gt;    backuptype=rsync&lt;br /&gt;&lt;br /&gt;You can backup to a remote host or save the files locally.&lt;br /&gt;    [fs]&lt;br /&gt;    backupdir=/mnt/backup/mysql&lt;br /&gt;    [misc]&lt;br /&gt;    backuptype=rsync&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1198368836367832042?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1198368836367832042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1198368836367832042&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1198368836367832042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1198368836367832042'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/backup-using-mylvmbackup.html' title='Backup using mylvmbackup'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-378770490827538651</id><published>2010-08-18T03:35:00.000-07:00</published><updated>2010-08-18T03:37:21.038-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php tips'/><title type='text'>Memory loss</title><content type='html'>There are times when you see the following PHP error in the error log. &lt;br /&gt;&lt;br /&gt;[Mon Aug 02 14:28:11 2010] [error] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 292995097 bytes) in /var/www/html/text.inc on line 25, referer: https://yahoo.com/Compose.php?con_id=cand74035&lt;br /&gt;&lt;br /&gt;The usual fix for this problem is as follows. At the top of the compose.php page use the following statement.&lt;br /&gt;&lt;br /&gt;ini_set("memory_limit","200M");&lt;br /&gt;&lt;br /&gt;This will increase the memory allocation for the current page only.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-378770490827538651?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/378770490827538651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=378770490827538651&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/378770490827538651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/378770490827538651'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/memory-loss.html' title='Memory loss'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4360013240264916571</id><published>2010-08-18T03:27:00.001-07:00</published><updated>2010-08-18T03:27:54.426-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Disable or enable logging</title><content type='html'>When you are restoring data from a dump file, the logging needs to be disabled. Here are 2 shell scripts that will disable (or enable) the binary, slow and general logs completely. The mysql service needs to be restarted after you run this script.&lt;br /&gt;&lt;br /&gt;If you do not want to restart the mysql service then login to mysql prompt and type...&lt;br /&gt;mysql&gt; set sql_log_bin = 0;&lt;br /&gt;mysql&gt; use DB_Name;&lt;br /&gt;mysql&gt; source dumpfile.sql;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# cat enable_logs.sh &lt;br /&gt;#/bin/sh&lt;br /&gt;# enable logs by removing the comment&lt;br /&gt;# first backup the current my.cnf&lt;br /&gt;cp /etc/my.cnf /home/develop/my_$(date +'%d-%m-%y-%H-%M').cnf&lt;br /&gt;&lt;br /&gt;sed -i "s/^#log-slow-queries=/log-slow-queries=/" /etc/my.cnf&lt;br /&gt;sed -i "s/^#log-bin=/log-bin=/" /etc/my.cnf&lt;br /&gt;#sed -i "s|^log=.*$|#\\0|" /home/develop/development.cnf &lt;br /&gt;# general logs are disable&lt;br /&gt;&lt;br /&gt;# restart mysql service&lt;br /&gt;#/etc/init.d/mysql restart&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# cat disable_logs.sh &lt;br /&gt;#/bin/sh&lt;br /&gt;# disable logs by adding the comment&lt;br /&gt;# backup the current my.cnf file to develop subfolder&lt;br /&gt;cp /etc/my.cnf /home/develop/my_$(date +'%d-%m-%y-%H-%M').cnf&lt;br /&gt;&lt;br /&gt;sed -i "s|^log-slow-queries=.*$|#\\0|" /etc/my.cnf&lt;br /&gt;sed -i "s|^log-bin=.*$|#\\0|" /etc/my.cnf&lt;br /&gt;#sed -i "s|^log=.*$|#\\0|" /home/develop/development.cnf &lt;br /&gt;# general logs are disabled&lt;br /&gt;&lt;br /&gt;# restart mysql service&lt;br /&gt;#/etc/init.d/mysql restart&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4360013240264916571?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4360013240264916571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4360013240264916571&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4360013240264916571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4360013240264916571'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/disable-or-enable-logging.html' title='Disable or enable logging'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-989891438630678185</id><published>2010-08-18T02:30:00.000-07:00</published><updated>2010-08-18T02:32:07.387-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='php tips'/><title type='text'>Extract of Apache error log</title><content type='html'>There are times when you need to check the latest entries in the apache error log.&lt;br /&gt;Here is the easy way to do so.&lt;br /&gt; &lt;br /&gt;Cron entry:&lt;br /&gt;# extract of apache error log &lt;br /&gt;# updated every 5 minutes and posted to http://yourSite.com/shantanu/index.txt&lt;br /&gt;*/5 * * * * sh /home/develop/apache.sh &gt;&gt; /home/develop/apache_succ.txt 2&gt;&gt; /home/develop/apache_err.txt&lt;br /&gt;&lt;br /&gt;Shell script:&lt;br /&gt;&lt;br /&gt;# cat /home/develop/apache.sh &lt;br /&gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;mytemp='/home/develop/mytemp.txt'&lt;br /&gt;mypath='/home/develop/index.txt'&lt;br /&gt;&gt; $mypath&lt;br /&gt;&gt; $mytemp&lt;br /&gt;&lt;br /&gt;for file in `find /var/log/httpd/ -name "*log"`&lt;br /&gt;do &lt;br /&gt;tail -100 $file | grep "`date +%h\ %d`"  &gt;&gt; $mytemp&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;sed -i '/^$/d' $mytemp&lt;br /&gt;grep -v 'favicon' $mytemp &gt; $mypath&lt;br /&gt;mv $mypath /var/www/html/shantanu/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-989891438630678185?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/989891438630678185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=989891438630678185&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/989891438630678185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/989891438630678185'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/extract-of-apache-error-log.html' title='Extract of Apache error log'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5707214386506421478</id><published>2010-08-18T01:59:00.000-07:00</published><updated>2010-08-18T02:21:12.645-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Processlist snapshot</title><content type='html'>You can check the slow query log to find the query that is taking too long to complete. But What if you want to see the entire processlist at that time?&lt;br /&gt;Here is the shell script that will do the needful. You will have to add it to cron like this...&lt;br /&gt;# log high processes&lt;br /&gt;*/10 * * * * sh /home/develop/log_process.sh &gt;&gt; /home/develop/kill_process.txt 2&gt;&gt; /home/develop/kill_proc_err.txt&lt;br /&gt;&lt;br /&gt;# cat log_process.sh &lt;br /&gt;#!/bin/bash&lt;br /&gt;SEC=100&lt;br /&gt;mnumber=919702977470&lt;br /&gt;IFS='|'&lt;br /&gt;&lt;br /&gt;mysqladmin proc -v|grep Query|grep -Evi "delete|update|insert|alter table" |while read dummy qid qusr qhost qdb qstat qsec qstat2 query&lt;br /&gt;do&lt;br /&gt;if [ $qsec -gt $SEC ]; then&lt;br /&gt;&lt;br /&gt;echo `date`&lt;br /&gt;echo " "&lt;br /&gt;echo `mysqladmin proc`&lt;br /&gt;# mysqladmin kill $qid&lt;br /&gt;# echo "Killed query $qid..."&lt;br /&gt;echo "##############################"&lt;br /&gt;echo "##############################"&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [ $qsec -gt $SEC ]; then&lt;br /&gt;&lt;br /&gt;curl -Ld'username=SomeUser&amp;password=PassWord&amp;source=oksoft&amp;dmobile='$mnumber'&amp;message=process running more than 1000 seconds on QA DB server' http://67.23.229.95&lt;br /&gt;/smsclient//api.php&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;done&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5707214386506421478?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5707214386506421478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5707214386506421478&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5707214386506421478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5707214386506421478'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/processlist-snapshot.html' title='Processlist snapshot'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7707282568865911750</id><published>2010-08-18T01:52:00.001-07:00</published><updated>2010-08-18T01:53:10.548-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>mysqlreport</title><content type='html'>mysqlreport makes a friendly report of important MySQL status values. mysqlreport transforms the values from SHOW STATUS into an easy-to-read report that provides an in-depth understanding of how well MySQL is running. mysqlreport is a better alternative to manually interpreting SHOW STATUS.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://hackmysql.com/mysqlreport"&gt;http://hackmysql.com/mysqlreport&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7707282568865911750?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7707282568865911750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7707282568865911750&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7707282568865911750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7707282568865911750'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/mysqlreport.html' title='mysqlreport'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5771741795441385596</id><published>2010-08-18T01:44:00.000-07:00</published><updated>2010-08-18T01:45:44.952-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Partitions problem</title><content type='html'>This is how a typical server look like...&lt;br /&gt;&lt;br /&gt;# df -HP&lt;br /&gt;Filesystem             Size   Used  Avail Use% Mounted on&lt;br /&gt;/dev/hda8              1.1G   502M   489M  51% /&lt;br /&gt;/dev/hda1              128M    11M   111M   9% /boot&lt;br /&gt;tmpfs                  1.1G      0   1.1G   0% /dev/shm&lt;br /&gt;/dev/hda7              1.1G    44M   947M   5% /home&lt;br /&gt;/dev/hda3               27G    15G   9.8G  61% /mysql-bin-log&lt;br /&gt;/dev/hda2              105G    18G    82G  18% /mysql-data&lt;br /&gt;/dev/hda6              3.2G   1.1G   1.9G  36% /usr&lt;br /&gt;/dev/hda9               16G   4.7G    11G  32% /var&lt;br /&gt;&lt;br /&gt;The root / directory has space of only 1 GB and that is not enough. Mysql uses the /tmp folder to save its .sock file and other temporary files those are created at the time of alter and repair. There should be at least 10 GB space allocated for root.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5771741795441385596?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5771741795441385596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5771741795441385596&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5771741795441385596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5771741795441385596'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/partitions-problem.html' title='Partitions problem'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-348469477542210266</id><published>2010-08-18T01:38:00.001-07:00</published><updated>2010-08-18T01:38:35.822-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>disable trigger</title><content type='html'>There are times when you want to add some data in a table and the trigger on that table has some complex logic built-in. In order to disable the trigger temporarily, add a condition in your triggers like:&lt;br /&gt;&lt;br /&gt;if (@DISABLE_TRIGER IS NULL) then&lt;br /&gt;#trigger body&lt;br /&gt;end if;&lt;br /&gt;&lt;br /&gt;and than if you want to disable triggers on import just:&lt;br /&gt;&lt;br /&gt;SET @DISABLE_TRIGER=1;&lt;br /&gt;do imports&lt;br /&gt;SET @DISABLE_TRIGER=NULL;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-348469477542210266?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/348469477542210266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=348469477542210266&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/348469477542210266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/348469477542210266'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/disable-trigger.html' title='disable trigger'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8087055352392311826</id><published>2010-08-17T22:57:00.000-07:00</published><updated>2010-08-19T02:17:59.702-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Finding relations</title><content type='html'>Finding the relations within the tables is possible by looking into the mysql general log. Here is an example&lt;br /&gt;&lt;br /&gt;# grep -Eo '( *[^ ]* *){4}some_tbl_name( *[^ ]* *){4}' /mysql-bin-log/mysql-gen.log | head -10000 | sort -u&lt;br /&gt;&lt;br /&gt;In the example above, the table "accounts" is related to sourcing. You can add word boundaries like \less than sign and \greater than sign.&lt;br /&gt;Make sure that the general logs are enabled, before using the command.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8087055352392311826?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8087055352392311826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8087055352392311826&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8087055352392311826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8087055352392311826'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/finding-relations.html' title='Finding relations'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5102369433719162406</id><published>2010-08-17T00:13:00.000-07:00</published><updated>2010-08-17T00:18:02.396-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Repair broken tables</title><content type='html'>You can find out the names of corrupt tables from the error log and repair them.&lt;br /&gt;&lt;br /&gt;tail -10000 `grep 'error=' /etc/my.cnf | awk -F'=' '{print $2}'` | grep "`date +%y%m%d`" | awk -F"ERROR" '{print $2}' | sort -u | sed -e "s/.*\.\//REPAIR TABLE /g" -e "s/[\\.'].*/;/g" -e "s/\//./"&lt;br /&gt;&lt;br /&gt;It will grab the error log location from the my.cnf file. The statement above will output the "repair table db.tbl;" statements. You can pass them on to mysql using&lt;br /&gt; | mysql -f&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5102369433719162406?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5102369433719162406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5102369433719162406&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5102369433719162406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5102369433719162406'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/repair-broken-tables.html' title='Repair broken tables'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-570744006292472938</id><published>2010-08-16T23:53:00.000-07:00</published><updated>2010-08-19T05:01:53.301-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Finding optimum column width</title><content type='html'>I have a column "fromadd" in the table headers. The table exist in all the databases. How do I find out what is the maximum length of data that has been stored in this column?&lt;br /&gt;&lt;br /&gt;# cat whycorrupt.sh &lt;br /&gt;#!/bin/sh&lt;br /&gt;&lt;br /&gt;mypath='/home/develop/toprocess.txt'&lt;br /&gt;&gt; $mypath&lt;br /&gt;&lt;br /&gt;for dbname in `mysqlshow`&lt;br /&gt;do&lt;br /&gt;mysql -e"select * from $dbname.headers procedure analyse ()\G" &gt;&gt; $mypath&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;echo "fromadd"&lt;br /&gt;grep -A4 'fromadd' toprocess.txt | grep 'Max_length' | sort -nrk2 | head&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above script will output something like this...&lt;br /&gt;&lt;br /&gt;fromadd&lt;br /&gt;             Max_length: 120&lt;br /&gt;             Max_length: 119&lt;br /&gt;             Max_length: 119&lt;br /&gt;             Max_length: 119&lt;br /&gt;             Max_length: 119&lt;br /&gt;             Max_length: 116&lt;br /&gt;             Max_length: 107&lt;br /&gt;             Max_length: 70&lt;br /&gt;             Max_length: 70&lt;br /&gt;             Max_length: 68&lt;br /&gt;&lt;br /&gt;Now I can set varchar(200) for the column "fromadd". I can use the same loop mentioned above to run the alter table statement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;You can create a text file with all the details of the Max and minimum values stored in that table. You will have to supply the Database name as the first positional parameter.&lt;br /&gt;&lt;br /&gt;$ sh proan.sh dbName&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&gt; max.txt&lt;br /&gt;&lt;br /&gt;mysqlshow $1 --count &gt;&gt; max.txt&lt;br /&gt;while read tblname ; do&lt;br /&gt;&lt;br /&gt;mysql -e"select '$tblname' as tableName, count(*) as count from $tblname" &gt;&gt; max.txt&lt;br /&gt;mysql -e"show create table $tblname\G" &gt;&gt; max.txt&lt;br /&gt;mysql -e"select * from $tblname procedure analyse()\G" &gt;&gt; max.txt&lt;br /&gt;&lt;br /&gt;done &lt;&lt;HERE&lt;br /&gt; `mysql -BNe"select CONCAT(TABLE_SCHEMA, '.' , TABLE_NAME) as noname from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '$1'"`&lt;br /&gt;&lt;br /&gt;HERE&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-570744006292472938?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/570744006292472938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=570744006292472938&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/570744006292472938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/570744006292472938'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/finding-optimum-column-width.html' title='Finding optimum column width'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4939997004781226654</id><published>2010-08-16T05:17:00.000-07:00</published><updated>2010-08-18T03:38:28.654-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><category scheme='http://www.blogger.com/atom/ns#' term='php tips'/><title type='text'>Timezone error in apache</title><content type='html'>There are times when you see the following error in the apache error log.&lt;br /&gt;&lt;br /&gt;[Sun Aug 08 14:06:12 2010] [error] [client 199.199.199.199] PHP Strict Standards:  date() [&lt;a href='function.date'&gt;function.date&lt;/a&gt;]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /var/www/html/global_fun.inc on line 524, referer: https://yahoo.com/edit.php?acc=deliver&amp;addr=543&lt;br /&gt;&lt;br /&gt;This is because of timezone mismatch.&lt;br /&gt;&lt;br /&gt;You can export the time zone variable as shown below.&lt;br /&gt;export TZ="America/New_York"&lt;br /&gt;&lt;br /&gt;Or add it to the php.ini file.&lt;br /&gt;&lt;br /&gt;[Date]&lt;br /&gt;; Defines the default timezone used by the date functions&lt;br /&gt;date.timezone = America/New_York&lt;br /&gt;&lt;br /&gt;Or else, set the timezone in the code itself.&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;date_default_timezone_set('America/New_York');&lt;br /&gt; echo date('D,F j, Y, h:i:s A');&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can check the current time in the following file.&lt;br /&gt;&lt;br /&gt;# cat /etc/sysconfig/clock&lt;br /&gt;ZONE="America/New_York"&lt;br /&gt;UTC=true&lt;br /&gt;ARC=false&lt;br /&gt;&lt;br /&gt;The following file shows that we are not sure about the current localtime. It is probably taking the time from system clock.&lt;br /&gt;&lt;br /&gt;# ls -l /etc/localtime &lt;br /&gt;-rw-r--r-- 1 root root 1267 Mar  5  2008 /etc/localtime&lt;br /&gt;&lt;br /&gt;The localtime file needs to be linked to the correct time zone.&lt;br /&gt;ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime&lt;br /&gt;&lt;br /&gt;All the above examples use America (New York) timezone has default one. You will have to change it if you need a different zone.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4939997004781226654?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4939997004781226654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4939997004781226654&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4939997004781226654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4939997004781226654'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/timezone-error-in-apache.html' title='Timezone error in apache'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6980002848324654901</id><published>2010-08-16T04:36:00.001-07:00</published><updated>2010-08-16T04:36:55.887-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Table size</title><content type='html'>You can check the size of the table using the following query. If it is a myisam table, you can check the actual file size on disk.&lt;br /&gt;&lt;br /&gt;# mysql -e"SELECT COUNT(*) TABLES,&lt;br /&gt;&gt;        SUM(table_rows) rows,&lt;br /&gt;&gt;        SUM(data_length) DATA,&lt;br /&gt;&gt;        SUM(index_length) idx,&lt;br /&gt;&gt;        SUM(data_length + index_length) total_size&lt;br /&gt;&gt; FROM   information_schema.TABLES where table_schema = 'customers' and table_name = 'mail_headers'"&lt;br /&gt;+--------+------+--------+--------+------------+&lt;br /&gt;| TABLES | rows | DATA   | idx    | total_size |&lt;br /&gt;+--------+------+--------+--------+------------+&lt;br /&gt;|      1 | 1695 | 518708 | 270336 |     789044 | &lt;br /&gt;+--------+------+--------+--------+------------+&lt;br /&gt;&lt;br /&gt;# ls -l /mysql-data/customers/mail_headers.*&lt;br /&gt;-rw-rw---- 1 mysql mysql   9460 Aug 16 06:39 /mysql-data/customers/mail_headers.frm&lt;br /&gt;-rw-rw---- 1 mysql mysql 518708 Aug 16 06:39 /mysql-data/customers/mail_headers.MYD&lt;br /&gt;-rw-rw---- 1 mysql mysql 270336 Aug 16 06:39 /mysql-data/customers/mail_headers.MYI&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The same query can be used to know the total size of the database. You have to remove the table_name clause. You can simply check the disk consumption if all the tables are myisam.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# mysql -e"SELECT COUNT(*) TABLES,              &lt;br /&gt;       SUM(table_rows) rows,&lt;br /&gt;       SUM(data_length) DATA,&lt;br /&gt;       SUM(index_length) idx,&lt;br /&gt;       SUM(data_length + index_length) total_size&lt;br /&gt;FROM   information_schema.TABLES where table_schema = 'customers'"&lt;br /&gt;+--------+-------+-----------+---------+------------+&lt;br /&gt;| TABLES | rows  | DATA      | idx     | total_size |&lt;br /&gt;+--------+-------+-----------+---------+------------+&lt;br /&gt;|    496 | 28406 | 274267486 | 4054016 |  278321502 | &lt;br /&gt;+--------+-------+-----------+---------+------------+&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# du -h /mysql-data/customers&lt;br /&gt;274M    /mysql-data/customers&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6980002848324654901?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6980002848324654901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6980002848324654901&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6980002848324654901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6980002848324654901'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/table-size.html' title='Table size'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-1965522580110979690</id><published>2010-08-12T21:29:00.000-07:00</published><updated>2010-08-12T21:31:34.819-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>To comma or not to comma</title><content type='html'>This is related to the discussion on comma joins.&lt;br /&gt;&lt;br /&gt;http://www.mysqlperformanceblog.com/2010/04/14/is-there-a-performance-difference-between-join-and-where/&lt;br /&gt;&lt;br /&gt;Here are a few points to note:&lt;br /&gt;&lt;br /&gt;1) "Inner join" syntax is ANSI compliant. Using the standard way of writing queries is better.&lt;br /&gt;&lt;br /&gt;2) When you need to rewrite the comma syntax to left join, it will have to re-code the whole structure and adopt the join syntax.&lt;br /&gt;&lt;br /&gt;SELECT * FROM A,B WHERE A.id = B.id and A.x=123;&lt;br /&gt;&lt;br /&gt;If you have already written the above query, it will be difficult to write the left join as shown below.&lt;br /&gt;SELECT * FROM A LEFT OUTER JOIN B ON A.id=B.id WHERE A.x=123;&lt;br /&gt;&lt;br /&gt;If you had written the inner join as shown below, it is easy to change to Left join.&lt;br /&gt;SELECT * FROM A INNER JOIN B ON A.id = B.id WHERE A.x=123&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) In the following example, isn't it difficult to find the relations between tables?&lt;br /&gt;&lt;br /&gt;SELECT * FROM A, B, C, D WHERE  A.x=123, &lt;br /&gt;B.DATE &gt; CURDATE()&lt;br /&gt;...&lt;br /&gt;some more conditions&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;D.id = C.id and&lt;br /&gt;C.id = B.id and&lt;br /&gt;A.id = B.id &lt;br /&gt;&lt;br /&gt;Isn't the following much easy to read and understand?&lt;br /&gt;&lt;br /&gt;SELECT * FROM A &lt;br /&gt;INNER JOIN B ON B.id = A.id &lt;br /&gt;INNER JOIN C C.id = B.id&lt;br /&gt;INNER JOIN D D.id = C.id&lt;br /&gt;WHERE  A.x=123, B.DATE &gt; CURDATE()&lt;br /&gt;&lt;br /&gt;I prefer that the column of table that is being joined come first in the sequence and therefore B.id = A.id and not A.id = B.id though both are the same.&lt;br /&gt;&lt;br /&gt;4) The forth point is that if I forget to add the comma, it becomes a table alias and things become difficult to find what went wrong.&lt;br /&gt;&lt;br /&gt;SELECT * FROM A  B WHERE  B.id=123;&lt;br /&gt;&lt;br /&gt;The above is a perfectly valid query but with wrong results since the table A is aliased as B!!&lt;br /&gt;&lt;br /&gt;5) Updates&lt;br /&gt;We need to join tables not just in "select", but in updates too. The update statement can be written using comma joins. But see the difference between these two queries and decide which one would you prefer.&lt;br /&gt;&lt;br /&gt;UPDATE phpbb2_posts_text A, phpbb3_posts3 B -- implicit comma join&lt;br /&gt;SET B.bbcode_uid=A.bbcode_uid&lt;br /&gt;  , B.post_subject=A.post_subject&lt;br /&gt;  , B.post_text=A.post_text&lt;br /&gt;WHERE A.somecolumn = B.somecolumn&lt;br /&gt;  AND B.post_id&lt;=218727&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;UPDATE phpbb2_posts_text A&lt;br /&gt;INNER &lt;br /&gt;  JOIN phpbb3_posts3 B -- explicit join&lt;br /&gt;    ON A.somecolumn = B.somecolumn&lt;br /&gt;SET B.bbcode_uid=A.bbcode_uid&lt;br /&gt;  , B.post_subject=A.post_subject&lt;br /&gt;  , B.post_text=A.post_text&lt;br /&gt;WHERE B.post_id&lt;=218727&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-1965522580110979690?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/1965522580110979690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=1965522580110979690&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1965522580110979690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/1965522580110979690'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/to-comma-or-not-to-comma.html' title='To comma or not to comma'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-2069650689658348773</id><published>2010-08-10T22:45:00.001-07:00</published><updated>2010-11-29T23:17:49.749-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><title type='text'>Unix Power</title><content type='html'>Here are 2 important tips.&lt;br /&gt;&lt;br /&gt;A) Create a verbatim copy of any directory, including symbolic links, with tar:&lt;br /&gt;&lt;br /&gt;tar cf - /path/to/original |  \&lt;br /&gt;  (mkdir -p /path/to/copy; cd /path/to/copy; tar xvf -)&lt;br /&gt;&lt;br /&gt;The first tar archives the directory /path/to/original and emits the archive file to stdout; the hyphen (-) used with the create (c) option specifies stdout. The command in parentheses is a subshell: Commands in the subshell don't affect the environment of the current shell. mkdir -p creates the named directory, including any intermediate directories that need to be created; and cd changes to the new directory. The second tar reads an archive from stdin and expands it in place; the hyphen used with the extract (x) option refers to stdin.&lt;br /&gt;&lt;br /&gt;B) find all Web pages on your server that reference www.example.com, you can use this command line:&lt;br /&gt;&lt;br /&gt;% find / -name '*html' -print \&lt;br /&gt;  | xargs grep -l 'www.example.com' \&lt;br /&gt;  | less -Opages&lt;br /&gt;&lt;br /&gt;xargs consumes the filenames from find and runs grep -l repeatedly to process every file, no matter how many files are named. (grep -l prints the name of the file if a match is found and then stops further matching in that file.) less allows you to page through the results and saves the list in the file named pages. The result is a list of filenames that contain the string "www.example.com".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-2069650689658348773?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/2069650689658348773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=2069650689658348773&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2069650689658348773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/2069650689658348773'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/unix-power.html' title='Unix Power'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-3061163926660450509</id><published>2010-08-10T02:33:00.001-07:00</published><updated>2010-08-10T02:34:50.522-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>skip name resolve</title><content type='html'>There are 2 ways of granting access to the database. One is allow an IP address to log-in or a host name to access the database.&lt;br /&gt;&lt;br /&gt;grant all on *.* to 'redhat'@'10.0.2.143' identified by 'SecRet';&lt;br /&gt;grant all on *.* to 'redhat'@'mysite.net' identified by 'SecRet';&lt;br /&gt;&lt;br /&gt;The first method mentioned above is very popular and it's versatile as well. For e.g. I can use wildcard 192.168.% to allow access from all the machines of the network. The second method involves a lookup of hostname and this extra step takes time. There are times when the DNS server is down and mysql goes down as well for no fault of itself. The people can not figure out the reason.&lt;br /&gt;&lt;br /&gt;1) Use only IP "numbers" in the grant statement. Do not use hostname "text".&lt;br /&gt;2) use skip-name-resolve line in the my.cnf so that mysql will allow quick connections.&lt;br /&gt;&lt;br /&gt;I have experienced as much as 15% improvement in overall performance and less frequent downtime.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-3061163926660450509?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/3061163926660450509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=3061163926660450509&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3061163926660450509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/3061163926660450509'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/skip-name-resolve.html' title='skip name resolve'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-7506928437106329461</id><published>2010-08-09T21:16:00.000-07:00</published><updated>2010-11-29T23:17:49.751-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><title type='text'>vi tips and tricks</title><content type='html'>Numbering&lt;br /&gt;:set number&lt;br /&gt;:set nonumber &lt;br /&gt;&lt;br /&gt;Indent&lt;br /&gt;:set autoindent&lt;br /&gt;:set noautoindent &lt;br /&gt;&lt;br /&gt;Case Sensitivity&lt;br /&gt;:set ignorecase &lt;br /&gt;:set noignorecase&lt;br /&gt;If you want to ignore case sensitivity on searches every time you enter a vi session, you can add the line set ignorecase to the .exrc file in your home directory. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Search&lt;br /&gt;/echo&lt;br /&gt;to seach for the word echo&lt;br /&gt;/echo.*file&lt;br /&gt;to search for the word echo followed by the word file&lt;br /&gt;&lt;br /&gt;Bookmarks&lt;br /&gt;You can tell vi to place a bookmark at a point in a file by pressing the Escape key followed by the M key followed by another alphabetic character that denotes the bookmark reference. Therefore, you have up to 26 bookmarks named a to z. To return to the previous bookmark, press the Escape key followed by the back tick (`) followed by the bookmark reference alphabetic character. &lt;br /&gt;&lt;br /&gt;Execute UNIX command&lt;br /&gt;:!pwd &lt;br /&gt;&lt;br /&gt;Filtering&lt;br /&gt;:1,$!sort &lt;br /&gt;# pass lines 1 through the end of the file ($) into the sort command&lt;br /&gt;:1,$!awk '{print $1}' | sort | tr [:lower:] [:upper:]&lt;br /&gt;4!!awk '{print "New text",$0}'&lt;br /&gt;&lt;br /&gt;Section save&lt;br /&gt;:6,9w &gt;&gt; /tmp/newfile&lt;br /&gt;You can use the $  notation for the last line to specify to the end of the file&lt;br /&gt;&lt;br /&gt;// Delete DOS Characters via VIM (^M)&lt;br /&gt;:set ff=unix&lt;br /&gt;:set ff=dos&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-7506928437106329461?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/7506928437106329461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=7506928437106329461&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7506928437106329461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/7506928437106329461'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/vi-tips-and-tricks.html' title='vi tips and tricks'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-5698870869484337483</id><published>2010-08-08T23:27:00.000-07:00</published><updated>2010-08-08T23:28:19.483-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Altering huge table</title><content type='html'>CREATE TABLE `testhack` (&lt;br /&gt;`id` int(11) NOT NULL DEFAULT '0',&lt;br /&gt;`unq` varchar(100) DEFAULT NULL,&lt;br /&gt;`keyword` varchar(250) DEFAULT NULL,&lt;br /&gt;PRIMARY KEY (`id`),&lt;br /&gt;UNIQUE KEY `unq` (`unq`)&lt;br /&gt;) ENGINE=MyISAM&lt;br /&gt;&lt;br /&gt;I need to drop the unique key. So, i create a new table testhack_new with the following schema&lt;br /&gt;&lt;br /&gt;CREATE TABLE `testhack_new` (&lt;br /&gt;`id` int(11) NOT NULL DEFAULT '0',&lt;br /&gt;`unq` varchar(100) DEFAULT NULL,&lt;br /&gt;`keyword` varchar(250) DEFAULT NULL,&lt;br /&gt;PRIMARY KEY (`id`)&lt;br /&gt;) ENGINE=MyISAM&lt;br /&gt;&lt;br /&gt;mysql&gt; Flush tables with read lock;&lt;br /&gt;&lt;br /&gt;Open another terminal. And go to the mysql/data/&lt;database&gt; directory. Do the following:&lt;br /&gt;&lt;br /&gt;$ mv testhack.frm testhack_old.frm; mv testhack_new.frm testhack.frm; mv testhack_old.frm testhack_new.frm; &lt;br /&gt;&lt;br /&gt;$ mv testhack.MYI testhack_old.MYI; mv testhack_new.MYI testhack.MYI; mv testhack_old.MYI testhack_new.MYI;&lt;br /&gt;&lt;br /&gt;So, what is happening here is that the index, table definitions are being switched. After this process, the table definition of testhack will not contain the unique key. Now unlock the tables in the main window. And run repair tables to remove any issues.&lt;br /&gt;&lt;br /&gt;mysql&gt; unlock tables;&lt;br /&gt;mysql&gt; repair tables testhack;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;http://jayant7k.blogspot.com/2010/06/mysql-hack-altering-huge-tables.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-5698870869484337483?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/5698870869484337483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=5698870869484337483&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5698870869484337483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/5698870869484337483'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/altering-huge-table.html' title='Altering huge table'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6787951531673597442</id><published>2010-08-05T04:17:00.000-07:00</published><updated>2010-08-06T01:02:20.123-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>restore DB script loadme.sh</title><content type='html'>If you need to restore database from the dump back files, here is a easy way to do so. You simply have to supply the database name and the SQL file name to this script and it will load the data on the localhost. If you want to restore data on a remote server don't forget to change the $myhost variable.&lt;br /&gt;&lt;br /&gt;# cat loadme.sh&lt;br /&gt;#!/bin/sh&lt;br /&gt;# the first parameter is the name of the database and&lt;br /&gt;# second parameter is the name of the sql file&lt;br /&gt;# you call the script using the following syntax&lt;br /&gt;# sh loadme.sh shantanu aug03_final.sql&lt;br /&gt;# if the .sql file is not in the current directory, supply the complete path&lt;br /&gt;&lt;br /&gt;myhost='localhost'&lt;br /&gt;myuser='root'&lt;br /&gt;mypassword=''&lt;br /&gt;&lt;br /&gt;# Check if the DB and file name is supplied&lt;br /&gt;# if missing, exit with the code 199&lt;br /&gt;&lt;br /&gt;missing=199&lt;br /&gt;&lt;br /&gt;if [ -z $1 ]&lt;br /&gt;then&lt;br /&gt;echo "DB and file name both are required"&lt;br /&gt; exit $missing&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [ -z $2 ]&lt;br /&gt;then&lt;br /&gt;echo "DB and file name both are required"&lt;br /&gt; exit $missing&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;# Create output file for results&lt;br /&gt;&lt;br /&gt;mydate=`date +'%d_%h_%Y_V-%H%M%S'`&lt;br /&gt;output="$1_$mydate".txt&lt;br /&gt;&gt; $output&lt;br /&gt;&lt;br /&gt;if [[ $mypassword ]];then&lt;br /&gt;mysql -h$myhost -u$myuser -p$mypassword -e"drop database if exists $1"&lt;br /&gt;mysqladmin -h$myhost -u$myuser -p$mypassword create $1&lt;br /&gt;time mysql -h$myhost -u$myuser -p$mypassword  $1 &lt; "$2"&lt;br /&gt;mysqlshow -h$myhost -u$myuser -p$mypassword  $1 --count &gt; $output&lt;br /&gt;else&lt;br /&gt;mysql -h$myhost -u$myuser -e"drop database if exists $1"&lt;br /&gt;mysqladmin -h$myhost -u$myuser create $1&lt;br /&gt;time mysql -h$myhost -u$myuser $1 &lt; "$2"&lt;br /&gt;mysqlshow -h$myhost -u$myuser $1 --count &gt; $output&lt;br /&gt;fi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6787951531673597442?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6787951531673597442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6787951531673597442&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6787951531673597442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6787951531673597442'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/restore-db-script-loadmesh.html' title='restore DB script loadme.sh'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-6394563846088486371</id><published>2010-08-02T05:56:00.001-07:00</published><updated>2011-09-22T23:51:47.615-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Extracting queries from binary files</title><content type='html'>There are times when you need to check the actual queries being executed. The best way is to open up the binary file and look into it.&lt;br /&gt;Here is the script that will do it for you.&lt;br /&gt;&lt;br /&gt;sh extract.sh tbl_name&lt;br /&gt;&lt;br /&gt;You have to supply the table name and call the shell script. -xv will enable the debug mode so that you can check if it running fine.&lt;br /&gt;&lt;br /&gt;# cat extract.sh&lt;br /&gt;#!/bin/sh&lt;br /&gt;# the my.cnf path should have the filename initials like&lt;br /&gt;# log-bin=/mysql-bin-log/db1-bin&lt;br /&gt;# find the binary path&lt;br /&gt;mypath=`grep log-bin /etc/my.cnf | awk -F'=' '{print $2}'`*.*&lt;br /&gt;&lt;br /&gt;# extract the latest binary file to a text file&lt;br /&gt;mysqlbinlog `ls $mypath -t | head -1` &gt; /home/bintext.txt&lt;br /&gt;&lt;br /&gt;# select the table name that is supplied as an argument&lt;br /&gt;grep -C2 "$1" /home/bintext.txt | tail -500 &gt; /home/tosend.txt&lt;br /&gt;# save the last 500 lines to a text file&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;** analyse binary files **&lt;br /&gt;You will get to see the insert/ update statements along with its count.&lt;br /&gt;You can supply the binary file name. The latest file is used as default. &lt;br /&gt;&lt;br /&gt;sh /bin/mylog&lt;br /&gt;OR&lt;br /&gt;sh /bin/mylog/ db1-bin.000223&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# cat /bin/mylog &lt;br /&gt;#!/bin/sh&lt;br /&gt; &lt;br /&gt;if [[ $1 ]];then&lt;br /&gt;&lt;br /&gt;mysqlbinlog ${1} | grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter" | cut -c1-100 | tr '[A-Z]' '[a-z]' | sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" | sort | uniq -c | sort -nr&lt;br /&gt;&lt;br /&gt;echo "table list from binary log ${1}"&lt;br /&gt;mysqlbinlog ${1} | grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter" | cut -c1-100 | tr '[A-Z]' '[a-z]' | sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" | replace 'insert into ' '' | replace 'delete from ' '' | replace 'update ' '' |  awk '{print $1}' | sort | uniq -c | sort -nr&lt;br /&gt;&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt;mypath=`grep log-bin /etc/my.cnf | awk -F'=' '{print $2}'`*.*&lt;br /&gt;latest=`ls $mypath -t | head -1`&lt;br /&gt;&lt;br /&gt;mysqlbinlog ${latest} | grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter" | cut -c1-100 | tr '[A-Z]' '[a-z]' | sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" | sort | uniq -c | sort -nr | head -50&lt;br /&gt;&lt;br /&gt;echo "table list from binary log ${1}"&lt;br /&gt;mysqlbinlog ${latest} | grep -i -e "^update" -e "^insert" -e "^delete" -e "^replace" -e "^alter" | cut -c1-100 | tr '[A-Z]' '[a-z]' | sed -e "s/\t/ /g;s/\`//g;s/(.*$//;s/ set .*$//;s/ as .*$//" | sed -e "s/ where .*$//" | replace 'insert into ' '' | replace 'delete from ' '' | replace 'update ' '' |  awk '{print $1}' | sort | uniq -c | sort -nr | head -30&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// If you are using row based binary logging, you need to decode the data&lt;br /&gt;mysqlbinlog --base64-output=decode-rows --verbose /var/lib/mysql/server-bin.000022&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-6394563846088486371?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/6394563846088486371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=6394563846088486371&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6394563846088486371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/6394563846088486371'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/extracting-queries-from-binary-files.html' title='Extracting queries from binary files'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8600955352907097957</id><published>2010-08-02T00:44:00.000-07:00</published><updated>2010-11-29T23:17:49.752-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux tips'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Analyse Corrupt Tables</title><content type='html'>If you are using myisam only table types then you must have come across tables those are being corrupt without any known reason. The following command shows that the tables (from several databases) those have crashed today.&lt;br /&gt;&lt;br /&gt;# tail -10000 /mysql-db-path/db1.err | grep `date "+%y%m%d"` | awk -F'ERROR' '{print $2}' | sort -u | awk -F"'" '{print $2}'&lt;br /&gt;./db1/mail_me&lt;br /&gt;./db2/mail_me&lt;br /&gt;./db3/customers&lt;br /&gt;&lt;br /&gt;In order to know why does only one table crashed and not any other table, we need to take a closer look at the table structure. The following comand will find the tables those are corrupt or going to be corrupted soon. You can add -r option to myisamchk to repair the tables on the fly.&lt;br /&gt;# find `grep 'datadir' /etc/my.cnf | awk -F"=" '{print $2}'` -not -name '#*.MYI' -name '*.MYI' -exec myisamchk -sF {} \;&lt;br /&gt;&lt;br /&gt;The options are:&lt;br /&gt;&lt;br /&gt;    * -s, --silent option: Prints only errors. You can use two -s to make myisamchk very silent.&lt;br /&gt;    * -f, --force option: Restart myisamchk automatically with repair option -r, if there are any errors in the table.&lt;br /&gt;    * -F, --fast option: Check only tables that haven?t been closed properly.&lt;br /&gt;    * -U --update-state option: Marks tables as crashed, when it finds any error.&lt;br /&gt;    * -r --recover: Can fix almost anything except unique keys that aren't unique.&lt;br /&gt;&lt;br /&gt;You will need add -f or -r to recover the corrupt tables. The command mentioned above can be added to the cron so that it will run every day and repair the corrupt tables automatically.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8600955352907097957?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8600955352907097957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8600955352907097957&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8600955352907097957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8600955352907097957'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/08/analyse-corrupt-tables.html' title='Analyse Corrupt Tables'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8456899369169955220</id><published>2010-07-31T01:56:00.001-07:00</published><updated>2010-07-31T01:58:20.578-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>using Functions instead of Joins</title><content type='html'>Here is an interesting way to join two tables, using function! I do not know why anyone will need to use this method though.&lt;br /&gt;&lt;br /&gt;drop table if exists hindi;&lt;br /&gt;drop table if exists english;&lt;br /&gt;create table hindi(id int, HindiWord varchar(100), primary key(id));&lt;br /&gt;create table english(id int, EnglishWord varchar(100), primary key(id));&lt;br /&gt;insert into hindi values ('1', 'ek'), ('2', 'do'), ('3', 'teen');&lt;br /&gt;insert into english values ('3', 'three'), ('4', 'four'), ('5', 'five');&lt;br /&gt;&lt;br /&gt;DROP FUNCTION IF EXISTS getEnglishName; &lt;br /&gt;delimiter ;;&lt;br /&gt;CREATE FUNCTION getEnglishName(EngId INT(15)) RETURNS VARCHAR(300) &lt;br /&gt;BEGIN &lt;br /&gt;DECLARE name VARCHAR(300) DEFAULT ''; &lt;br /&gt;select Englishword INTO name from english where id=EngId; &lt;br /&gt;return name; &lt;br /&gt;END;&lt;br /&gt;;;&lt;br /&gt;&lt;br /&gt;delimiter ;&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from hindi;&lt;br /&gt;+------+-----------+&lt;br /&gt;| id   | HindiWord |&lt;br /&gt;+------+-----------+&lt;br /&gt;|    1 | ek        | &lt;br /&gt;|    2 | do        | &lt;br /&gt;|    3 | teen      | &lt;br /&gt;+------+-----------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from english;&lt;br /&gt;+------+-------------+&lt;br /&gt;| id   | EnglishWord |&lt;br /&gt;+------+-------------+&lt;br /&gt;|    3 | three       | &lt;br /&gt;|    4 | four        | &lt;br /&gt;|    5 | five        | &lt;br /&gt;+------+-------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The "normal" way of joining tables is using the INNER JOIN syntax as shown below:&lt;br /&gt;&lt;br /&gt;mysql&gt; select a.id, a.HindiWord, b.EnglishWord from hindi as a inner join english as b on a.id = b.id;&lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;| id   | HindiWord | EnglishWord |&lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;|    3 | teen      | three       | &lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;1 row in set (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select a.id, a.HindiWord, b.EnglishWord from hindi as a left join english as b on a.id = b.id;&lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;| id   | HindiWord | EnglishWord |&lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;|    1 | ek        | NULL        | &lt;br /&gt;|    2 | do        | NULL        | &lt;br /&gt;|    3 | teen      | three       | &lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;3 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select a.id, a.HindiWord, b.EnglishWord from hindi as a left join english as b on a.id = b.id where b.id is null;&lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;| id   | HindiWord | EnglishWord |&lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;|    1 | ek        | NULL        | &lt;br /&gt;|    2 | do        | NULL        | &lt;br /&gt;+------+-----------+-------------+&lt;br /&gt;2 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;You can achive the same results of Inner, Left and Left Outer joins using function. The only difference is that the "NULL" value is not getting generated.&lt;br /&gt;&lt;br /&gt;mysql&gt; select a.id, a.HindiWord, getEnglishName(a.id) from hindi as a where getEnglishName(a.id) != '';&lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;| id   | HindiWord | getEnglishName(a.id) |&lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;|    3 | teen      | three                | &lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;1 row in set, 2 warnings (0.00 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select a.id, a.HindiWord, getEnglishName(a.id) from hindi as a;&lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;| id   | HindiWord | getEnglishName(a.id) |&lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;|    1 | ek        |                      | &lt;br /&gt;|    2 | do        |                      | &lt;br /&gt;|    3 | teen      | three                | &lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;3 rows in set, 2 warnings (0.01 sec)&lt;br /&gt;&lt;br /&gt;mysql&gt; select a.id, a.HindiWord, getEnglishName(a.id) from hindi as a where getEnglishName(a.id) = '';&lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;| id   | HindiWord | getEnglishName(a.id) |&lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;|    1 | ek        |                      | &lt;br /&gt;|    2 | do        |                      | &lt;br /&gt;+------+-----------+----------------------+&lt;br /&gt;2 rows in set, 4 warnings (0.00 sec)&lt;br /&gt;&lt;br /&gt;The query using function will not use indexes and hence the query will be slower than the standard join. But it is interesting to know different ways of joining data. I had a chance to see PHP code that used a loop to take one record from a table and join with the other. and yes, that too was inefficient way of joining tables.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8456899369169955220?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8456899369169955220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8456899369169955220&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8456899369169955220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8456899369169955220'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/07/using-functions-instead-of-joins.html' title='using Functions instead of Joins'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8078965909689008755</id><published>2010-07-31T01:08:00.001-07:00</published><updated>2010-08-05T01:49:30.614-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Enable and Disable logging</title><content type='html'>There are times when you need to stop logging the general queries as well as slow and binary queries. For e.g. when I am restoring data from a dump file, I do not want all the queries to enter in the log files for obvious reasons. &lt;br /&gt;Here is the simple shell script that will enable and disable the logs as and when required.&lt;br /&gt;&lt;br /&gt;$ cat disable_logs.sh&lt;br /&gt;#/bin/sh&lt;br /&gt;# disable logs by adding the comment&lt;br /&gt;# backup the current my.cnf first&lt;br /&gt;cp /etc/my.cnf /home/my_$(date +'%d-%m-%y-%H-%M').cnf&lt;br /&gt;sed -i "s|^log-slow-queries=.*$|#\\0|" /etc/my.cnf &lt;br /&gt;sed -i "s|^log-bin=.*$|#\\0|" /etc/my.cnf &lt;br /&gt;sed -i "s|^log=.*$|#\\0|" /etc/my.cnf &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$ cat enable_logs.sh&lt;br /&gt;#/bin/sh&lt;br /&gt;# enable logs by removing the comment&lt;br /&gt;# backup the current my.cnf first&lt;br /&gt;cp /etc/my.cnf /home/my_$(date +'%d-%m-%y-%H-%M').cnf&lt;br /&gt;sed -i "s/^#log-slow-queries=/log-slow-queries=/" /etc/my.cnf &lt;br /&gt;sed -i "s/^#log-bin=/log-bin=/" /etc/my.cnf &lt;br /&gt;sed -i "s/^#log=/log=/" /etc/my.cnf&lt;br /&gt;&lt;br /&gt;Restart the MySQL service after running this script.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8078965909689008755?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8078965909689008755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8078965909689008755&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8078965909689008755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8078965909689008755'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/07/enable-and-disable-logging.html' title='Enable and Disable logging'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4881065634594534133</id><published>2010-07-28T22:56:00.000-07:00</published><updated>2010-08-05T01:49:49.486-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell script'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql tips'/><title type='text'>Primary requirement of a database</title><content type='html'>Every table in your database should have a primary key. A table without the primary key is like an orphan child without the support of parents or a youth without a spouse. You never know what you are missing!&lt;br /&gt;&lt;br /&gt;1) You can easily check if the table has a primary key or not.&lt;br /&gt;show create table tblName;&lt;br /&gt;&lt;br /&gt;2) Once you have found that there is no primary key, you must check if a column or a group of columns can be declared as a primary key.&lt;br /&gt;ALTER TABLE `tblName` ADD PRIMARY KEY ( `myID` , `yourID` , `type` ) &lt;br /&gt;&lt;br /&gt;3) If there is no such candidate column or a group of columns that is Unique and not null, you can simply add an auto-incremented column as shown below.&lt;br /&gt;ALTER TABLE `tblName` add column autoID int not null auto_increment, add primary key (autoID)&lt;br /&gt;&lt;br /&gt;4) If you want to remove the newly added column autoID, you can simply use the following statement.&lt;br /&gt;ALTER TABLE `tblName`  drop primary key, drop column autoID&lt;br /&gt;&lt;br /&gt;This simple task can dramatically improve the performance and will make it compliant without affecting the application in any way.&lt;br /&gt;&lt;br /&gt;Use the following shell script to find out the candidate column that can be declared as Primary.&lt;br /&gt;&lt;br /&gt;# cat primary.sh&lt;br /&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# the script to find out the tables those do not have a primary key&lt;br /&gt;# It will show the max and min values stored in each column along with the create table output&lt;br /&gt;# change the dbname to the database name that you want to analyse&lt;br /&gt;dbname='shantanu'&lt;br /&gt;&gt; /home/develop/tosave.txt&lt;br /&gt;&lt;br /&gt;while read mytable&lt;br /&gt;do&lt;br /&gt;mysql shantanu -Bse"show create table $mytable\G" &gt;&gt; /home/develop/tosave.txt&lt;br /&gt;mysql shantanu -Bse"select * from $mytable procedure analyse()\G" &gt;&gt; /home/develop/tosave.txt&lt;br /&gt;&lt;br /&gt;done &lt;&lt; heredoc&lt;br /&gt; `mysql -Bse"select t.table_name as tbl from INFORMATION_SCHEMA.TABLES AS t  LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c ON (t.TABLE_NAME=c.TABLE_NAME AND c.CONSTRAINT_SCHEMA=t.TABLE_SCHEMA AND constraint_name='PRIMARY')  WHERE t.table_schema='$dbname' AND constraint_name IS NULL;"`&lt;br /&gt;heredoc&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;== need for Primary Key ==&lt;br /&gt;&lt;br /&gt;It is interesting to know what happens if we do not have a primary key to uniquely differnetiate the rows.&lt;br /&gt;Here is an example table.&lt;br /&gt;&lt;br /&gt;mysql&gt; select * from hari;&lt;br /&gt;+------+------------+-------+&lt;br /&gt;| id   | mydate     | email |&lt;br /&gt;+------+------------+-------+&lt;br /&gt;|    1 | 2009-10-10 | 1111  | &lt;br /&gt;|    1 | 2009-10-10 | 1111  | &lt;br /&gt;|    1 | 2009-10-10 | 2222  | &lt;br /&gt;|    2 | 2010-11-11 | 3333  | &lt;br /&gt;|    2 | 2010-11-11 | 3333  | &lt;br /&gt;+------+------------+-------+&lt;br /&gt;5 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;The problem with the above table is that the first 2 and last 2 rows are actually duplicate and there is no way to identify them since there is no unique or primary key used in the table.&lt;br /&gt;Here is the SQL code that you can run to create this test table.&lt;br /&gt;&lt;br /&gt;drop table if exists hari;&lt;br /&gt;CREATE TABLE `hari` (&lt;br /&gt;  `id` int(11) default NULL,&lt;br /&gt;  `mydate` date default NULL,&lt;br /&gt;  `email` varchar(100) default NULL&lt;br /&gt;) ENGINE=MyISAM DEFAULT CHARSET=latin1;&lt;br /&gt;INSERT INTO `hari` VALUES (1,'2009-10-10','1111'),(1,'2009-10-10','1111'),(1,'2009-10-10','2222'),(2,'2010-11-11','3333'),(2,'2010-11-11','3333');&lt;br /&gt;&lt;br /&gt;In order to get the count of the unique ID's we need the following query.&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;count(sel2.refid2 ) as recCount,&lt;br /&gt;refid2, recDate2&lt;br /&gt;FROM&lt;br /&gt;(SELECT id AS refid2, mydate AS recDate2&lt;br /&gt;FROM hari AS ol_Email1&lt;br /&gt;GROUP BY ol_Email1.id, ol_Email1.mydate, ol_Email1.email &lt;br /&gt;) AS sel2&lt;br /&gt;GROUP BY sel2.refid2;&lt;br /&gt;&lt;br /&gt;+----------+--------+------------+&lt;br /&gt;| recCount | refid2 | recDate2   |&lt;br /&gt;+----------+--------+------------+&lt;br /&gt;|        2 |      1 | 2009-10-10 | &lt;br /&gt;|        1 |      2 | 2010-11-11 | &lt;br /&gt;+----------+--------+------------+&lt;br /&gt;2 rows in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;The query shown above is ugly, confusing and slow since the indexes will not be used properly. So I add a primary key to the table.&lt;br /&gt;&lt;br /&gt;ALTER TABLE hari ADD COLUMN pid INT NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (pid);&lt;br /&gt;&lt;br /&gt;I get the same results as shown above, but with much cleaner query that is also using the primary key.&lt;br /&gt;&lt;br /&gt;select count(*) as ercCount, a.id as refid2, a.mydate as recDate2 from hari as a inner join &lt;br /&gt;(SELECT pid, id, mydate FROM hari GROUP BY id, mydate, email) as dt &lt;br /&gt;on a.pid = dt.pid group by a.id;&lt;br /&gt;&lt;br /&gt;+----------+--------+------------+&lt;br /&gt;| ercCount | refid2 | recDate2   |&lt;br /&gt;+----------+--------+------------+&lt;br /&gt;|        2 |      1 | 2009-10-10 | &lt;br /&gt;|        1 |      2 | 2010-11-11 | &lt;br /&gt;+----------+--------+------------+&lt;br /&gt;2 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/3043709-4881065634594534133?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4881065634594534133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4881065634594534133&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4881065634594534133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4881065634594534133'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/07/primary-requirement-of-database.html' title='Primary requirement of a database'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-8229110654539136070</id><published>2010-07-02T09:43:00.000-07:00</published><updated>2011-07-19T19:49:49.052-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><title type='text'>MySQL Schema Versioning and Migration Utility</title><content type='html'>&lt;a href="http://schemasync.org/"&gt;http://schemasync.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Schema Sync will generate the SQL necessary to migrate the schema of a source database to a target database (patch script), as well as a the SQL necessary to undo the changes after you apply them (revert script).&lt;br /&gt;&lt;br /&gt;_____&lt;br /&gt;&lt;br /&gt;MySQLdiff is another little Tool to detect layout differences between two databases.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.mysqldiff.org"&gt;http://www.mysqldiff.org&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Almost every developer knows that changes of the database on the development system have to be logged in order to update the live-system later on. &lt;br /&gt;To make this easier the tool MySQLdiff has been developed. MySQLdiff will create a SQL-ALTER-Script which has to be run onto the live-system to 'patch' it to the state of the development system.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-8229110654539136070?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/8229110654539136070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=8229110654539136070&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8229110654539136070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/8229110654539136070'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/07/mysql-schema-versioning-and-migration.html' title='MySQL Schema Versioning and Migration Utility'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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-3043709.post-4127743995459695253</id><published>2010-06-14T01:33:00.000-07:00</published><updated>2010-06-14T01:54:47.219-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>Error reporting page</title><content type='html'>With the Apache webserver it’s possible to use custom directives for your error script, place this code into your .htaccess file (place the file into the site root):&lt;br /&gt;&lt;br /&gt;ErrorDocument 400 /error.php?err=400&lt;br /&gt;ErrorDocument 401 /error.php?err=401&lt;br /&gt;ErrorDocument 403 /error.php?err=403&lt;br /&gt;ErrorDocument 404 /error.php?err=404&lt;br /&gt;ErrorDocument 500 /error.php?err=500&lt;br /&gt;&lt;br /&gt;We use for the custom error script the most common HTTP errors.&lt;br /&gt;&lt;br /&gt;The error.php file will display the custom error message based on the error number. It will also log the IP and referrer to a text file.&lt;br /&gt;&lt;br /&gt;http://docs.google.com/View?id=dddjxz53_477dwhdwqck&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3043709-4127743995459695253?l=oksoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oksoft.blogspot.com/feeds/4127743995459695253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3043709&amp;postID=4127743995459695253&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4127743995459695253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3043709/posts/default/4127743995459695253'/><link rel='alternate' type='text/html' href='http://oksoft.blogspot.com/2010/06/error-reporting-page.html' title='Error reporting page'/><author><name>shantanu</name><uri>http://www.blogger.com/profile/04386423685935921709</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>
