Wednesday, December 19, 2012

Some Basic Rules for choosing to use Indexing or not



- Indexes slow down inserts and updates, so you should use them carefully on columns that are FREQUENTLY updated.
- Indexes speed up where clauses and order by.
Remember to think about HOW your data is going to be used when building your tables.
There are a few other things to remember. If your table is very small, it's worse to use an index than to leave it out and just let it do a table scan. Indexes really only come in handy with tables that have a lot of rows.

Why indexes may hurt performance of mysql DB incase of INSERT statements?



Indexes slow down INSERTS because of the overhead required to update the index, but an update might not hurt depending on whether the update is changing the index or not.
Updates that don't change indexes won't incur that extra overhead.
An update is actually a combination of a read and a write.  If the read uses the index and the update doesn't change it, the update might even be faster instead of slower. 

Tuesday, November 27, 2012

svn: warning: cannot set LC_CTYPE locale



svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LC_CTYPE is UTF-8
svn: warning: please check that your locale name is correct


To fix above issues, simply create an environment variable LC_ALL and set it to 'C'. 

e.g., 

export LC_ALL=C


Thursday, November 8, 2012

Configuring Filezilla for Resuming File Upload


1. Go To Transfer Option On Top. 
2. Expand It,Click Default File Exits Action.
3. A small Window will come where u will see Download and Upload.
4. Expand Upload and click Resume File Transfer.

That's all you need to do. 

Cheers.

Wednesday, November 7, 2012

Change Timezone of Ubuntu Machine to UTC from Command line



1.  Open Terminal. 
2.  sudo dpkg-reconfigure tzdata
3.  Follow on screen instructions and select your preferred time zone. 


Simple.. Isn't It?

Saturday, October 27, 2012

What is NAT (Network Address Translation)?


When your firewall or router is configured so that all other devices on internet recognize your home/office servers as having a valid Public IP Address then such a configuration is said to be using NAT or IP masquerading. 

Why NAT?

1.  No one on the Internet knows your true IP address. Thus it protects your PCs by assigning them IP addresses from "private" IP address space that cannot be routed over the Internet. This prevents hackers from directly attacking your home systems because packets sent to the "private" IP will never pass over the Internet.

2.  Hundreds of PCs and servers behind a NAT device can masquerade as a single public IP address. This greatly increases the number of devices that can access the Internet without running out of "public" IP addresses.


NAT Configurations? 

You can configure NAT to be one to one in which you request your ISP to assign you a number of public IP addresses to be used by the Internet-facing interface of your firewall and then you pair each of these addresses to a corresponding server on your protected private IP network. You can also use many to one NAT, in which the firewall maps a single IP address to multiple servers on the network.





What are Private IP Addresses and what are their ranges?


Some IP Address ranges are meant only for private networks. These are never used or routed on the internet... these IP Address are called as Private IP address. 

Here are the IP ranges which are private:


10.0.0.0 - 10.255.255.255

172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255

There is one special IP address which is called the localhost IP Address. This IP address is defined as 127.0.0.1. Whether or not your computer have a network decide, your system will always have this IP address assigned to it.

Tuesday, October 23, 2012

Installing tomcat 7 on Ubuntu Server 12.04 (Precise Pangolin)


The easiest way to install tomcat7 on ubuntu Server 12.04 or Precise Pangolin is to use apt-get. 

Here is the command: 


sudo apt-get install tomcat7


If you already had tomcat6 earlier on this machine there might be issues with tomcat6-commons when running this. Make sure you remove tomcat6-common before running the above command. 


sudo apt-get remove tomcat6-common


Manual Install: 

1. Make sure you have JRE Installed on your machine. 

2.  Download Tomcat 7 tar.gz binary distribution

3.  Unpack it using tar xvzf apache-tomcat-7.0.29.tar.gz

4. Create a directory where you want to install it and them move the unpacked stuff there. For e.g., I've created a directory named /usr/share/tomcat7. Use below command to move it: 

sudo mv apache-tomcat-7.0.29/ /usr/share/tomcat7


5. Edit catalina.sh and add following lines: 

JAVA_HOME="/usr/lib/jvm/jdk-6u32"
JRE_HOME="/usr/lib/jvm/jdk-6u32/jre" 


6.  Start tomcat using below command 

sudo /usr/share/tomcat7/bin/catalina.sh run


That's It... Simply Isn't It?

Thursday, October 18, 2012

ubuntu 12.04 features list


Head Up Display (or HUD)

HUD integrates application menus into the desktop UI. With an application open, hit the Alt key to bring up the HUD. When the HUD is open, you can easily search your application menus based on keywords. This means you will not have to poke through application menus.

New privacy tool

With this tool you can figure out what exactly Unity records and what it doesn’t. You can turn recording off to completely disable the feature or you can specify what files and applications it can record.

Launchbar

It can now be set to auto-hide. Icons can be resized now. It is no longer set with the dodge window behavior. This caused a lot of issues when interacting with certain applications. The default behavior now is always on top.

Change to Unity Dash

Now, the Dash shows Recent Apps first, Recent Files next, and finally, Recent Downloads.

Video Lens

Unity Lenses allow you to easily organize items in the Unity Dash. If you open the Video Lens, you can select and play videos from a variety of sources, such as those from your local collection, YouTube movies, BBC iPlayer, and TED Talks. Open the Lens, do a search, and click on the video you want to view.

Rhythmbox default

Ubuntu is returning to Rhythmbox as the default music player. 

MyUnity

Ubuntu Unity will finally include a configuration tool for the desktop. This application was developed to provide full customization of Unity features, including the Unity Launcher, Dash, Panel, Desk, and Font. This tool was available for 11.04 and 11.10, but had to be installed from the Software Center. Now, MyUnity will be installed and ready for configuration by default.

Trackpad support

Owners of trackpads whose clickable button is built into the surface can now enjoy support for their device. Most new Synaptics trackpads are supported, as are Apple Macbook trackpads. Ubuntu 12.10 should also include support for Apple’s Magic Trackpads.

Wednesday, October 17, 2012

How do i know if my macbook has usb 3.0 Support?

USB 3 (also known as "SuperSpeed USB") is the latest USB standard which offers significant performance improvements over USB 2 ("Hi-Speed USB").

USB Transfer Rate Comparison: 

  • USB 3 - transfer data up to 5 Gbps.
  • USB 2 - transfer data up to 480 Mbps.  
  • USB 1.1 - transfer data up to 12 Mbps.

Use the System Information utility to find out if your MAC has USB 3.0 Support or not. 
  1. From the Apple () menu, choose About this Mac.  
  2. Click More Info.
  3. Click System Report.
  4. In the Hardware section of the System Report, click USB.
  5. You will see a USB 3 section and a USB 2 section. USB 3 devices will appear in the "USB 3.0 SuperSpeed" section. Other devices will appear in the "USB Hi-Speed" section.

Thursday, October 11, 2012

How can i tell if a MySQL query returned nothing in PHP?


Its simple.. use mysql_num_rows as shown below....


$query_req="SELECT * FROM customer";
$query_result=mysql_query($query_req);

if (mysql_num_rows($query_result) != 0)
{
   echo "More than 0 records were returned.";
}

Wednesday, October 3, 2012

mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)

I had my website running on CentOS.. but when I moved it to MAC OS X I started getting this weird error. After having spent a lot of time on troubleshooting.. I found a very simple solution to it... 

The problem is that mysql get's the location of socket file to use incorrect. In my case it was trying for socket file at /var/mysql however on my MAC the socket file are created at /tmp. 

All that I did to correct this problem was: 

1.  Goto /var
2.  Create a directory named mysql
3.  Create symbolic link named mysql.sock to /tmp/mysql.sock
     sudo ln -s /tmp/mysql.sock mysql.sock


Monday, October 1, 2012

How to Install PHP on a Mac


To install PHP on a MAC you first need to enable apache. Enabling apache on MAC OS X is pretty simply... All you need to do is go into System Preferences and enable "Web Sharing".

Once you do that... you need to change your apache configuration file to enable it to load the php module. Here are the 3 simply steps you need to follow:

1.  Navigate to /etc/apache2/
2.  vi httpd.conf and Uncomment #LoadModule php5_module libexec/apache2/libphp5.so
3.  Restart apache. 

This is it.. but you may want to backup your php.ini file before you make any changes to it. You can find php.ini in /private/etc. 


Tuesday, September 25, 2012

Adding directories to the Mac OS X PATH variable


See what's in the PATH variable
  Open Terminal -> Type echo $PATH

This will display whatever is set in the path variable. 

Add more directories to the PATH variable
    Open Terminal -> Type export PATH=new_directory:$PATH

This will add the new_directory to the PATH variable. If you want to make this change permanent simply redirect the above to your .profile file (You can find it in your home directory.. If not, you can simply create one). See below for an example of redirection... 

Open Terminal -> Type export PATH=new_directory:$PATH >> ~/.profile

Where can I find "make" for MAC OS X Lion


"make" command or utility to be precise is used to figure out which parts of a large program needs to be recompiled and issues commands to recompile them. It is not limited to just programs but can be used for any other instructions where some files need to be updated automatically.

To be able to use make you need to install the make utility and write a Makefile (describes the relationship between various files of your program and also has instructions/commands for updating them).

Generally "make" utility comes by default on any *nix platforms. But on MAC OS X it does not come by default. You need to install XCode and command line tools in order to get make as well as some other developer tools installed.

Earlier XCode installation itself installed make and other tools but now those need to be installed separately.. Here is what you need to do..

1.  Open XCode.
2.  Goto Preferences -> Downloads.
3.  Select Command Line Tools and click Install.

This will install command line tools which include make and other developer tools like gcc on your machine. 

Monday, September 24, 2012

Slow queries on Amazon RDS

Amazon does not give you direct access to its database server to view any log files (like slow query log files).. But since slow query logs are very much useful in production systems it does give you a view of them in mysql's slow_log table. 

Here are some steps you will have to follow to enable Slow Query Logging on RDS (By default it is not enabled): 

1.  Modify the DB Parameter group your RDS Instance is using. Enable "slow_query_log" parameter.  

2.  Modify long_query_time to few seconds. Basically it tells to log queries which takes more than this many seconds. 

3.  Wait till your RDS Instance tells you that it is syncing. Once the DB Parameter group and RDS Instance are in sync (takes around 1 min), you can see that mysql's, slow_log tables shows you detailed view of various queries and how much time those are taking. This will give you a better picture of you various queries you application is firing and you can improve them. 

Some points to remember: 

1.  Queries are logging for new connections.. For existing connections you would see that the queries are not logged. 

2.  If you want to clear this table, call stored procedure rds_rotate_slow_log. e.g., CALL rds_rotate_slow_log();

3.   When the above stored procedure is called, the existing data in slow_log is dumped to slow_log_backup. You can now dimply dump that table for futher analysis. 

4.  When you run rds_rotate_slow_log() again the data from slow_log_backup is cleared and fresh data from slow_log is dumped into it. 

5.  If you are working to improve performance of your application, you would also be interested in turning on "log_queries_not_using_index". This will basically dump queries which are not using index. If you index them you will notice performance benefits. 

6.  I could not find millisecond precision on RDS.. which means I cannot log queries which are taking less than 1 seconds which is kind of weird. I was more interested to know queries which are taking less time but their frequency is much more high... taking care of such queries would have been more beneficial to me.. 

Anyways,, I hope my learnings above will help you guys to some extent.... 

ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number


mysql> GRANT * ON *.* TO 'sgoswami'@'121.23.3.13' IDENTIFIED BY PASSWORD "test123";


ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number

MySql expects you to enter password in an encrypted format. test123 which is been passed above is not in encrypted format and hence the error. 

Use mysql console to find out encrypted value for this password and replace it within your query. 

For e.g., 


mysql> select password('test123');
+---------------------+
| password('test123') |
+---------------------+
| 39817a786ddf7333    | 
+---------------------+
1 row in set (0.00 sec)

mysql> 


Replace test123 in above query with the encrypted password shown above. Note when you login you should use test123 only and not the encrypted one. For security reasons, the password is always stored in encrypted format. 

So, your query should look like below now: 

mysql> GRANT * ON *.* TO 'sgoswami'@'121.23.3.13' IDENTIFIED BY PASSWORD "39817a786ddf7333";

Sunday, September 23, 2012

MySql Server for MAC os X Lion - 10.07


Installation

Till the date of writing this article there is no GA release package available for mysql Server for MAC OS X Lion or 10.7. The only package available are of the developmental release. One good thing though is that 10.6 package for mysql works equally well on 10.7. Follow below steps to setup 10.6 on your MAC OS X Lion:

1.  Download the MAC Disk Image for 10.6 MySql Server. Download from official MySql site: http://dev.mysql.com/downloads/mysql/

2.  Mount the disk image and install MySql package by double clicking it. The steps are simple.. so just keep on following on screen instructions from the installer. 

3.  Add /usr/local/mysql/bin to your path by editing .profile file.

4.  You can start MySQL server by running “/usr/local/mysql/bin/mysqld_safe &” from terminal but Disk image you downloaded also consists of Startup Package & Preferences Pane which allows you to start/stop MySQL server from System Preferences and even Automatically Start MySQL Server at Startup.

What does the Installation Package do?
 

The Mac OS X PKG of MySQL installs itself into `/usr/local/mysql-VERSION'

Note: /usr/local/mysql is just a symlink to /usr/local/mysql-version... So whenever you upgrade the symlink will remain same but it will start pointing to the new version that you have installed. This also means that if you want to migrate your data to the new version that you have just installed you will have to copy it manually. 

In addition to this, it also calls the grant tables in the `mysql' database by executing `mysql_install_db'.

About MySQLStartupItem Package

This installation of this package ensures that mysql automatically starts during system startup. So install this package only if you require to start mysql automatically on system startup.

This startup item gets installed into `/Library/StartupItems/MySQLCOM'. Startup Item installation adds a variable `MYSQLCOM=-YES-' to the system configuration file
`/etc/hostconfig'. If you want to disable the automatic startup of MySQL, simply change this variable to `MYSQLCOM=-NO-'.

On Mac OS X Server, the default MySQL installation bundled with the operating system uses the variable `MYSQL' in the `/etc/hostconfig' file. The Sun Microsystems, Inc. "Startup Item" installer disables this variable by setting it to `MYSQL=-NO-'. This avoids boot time conflicts with the `MYSQLCOM' variable used by the Sun Microsystems, Inc. "Startup Item".

Starting Mysql from Command Line

If you have installed the Startup Item, use this command:
     shell> sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

If you don't use the Startup Item, enter the following command sequence:
     shell> cd /usr/local/mysql
     shell> sudo ./bin/mysqld_safe

You should be able to connect to the MySQL server, for example, by running `/usr/local/mysql/bin/mysql'.

Adding Aliases for easy access

     alias mysql=/usr/local/mysql/bin/mysql
     alias mysqladmin=/usr/local/mysql/bin/mysqladmin

Above allows you to access mysql directly without having to remember the full paths. 

Thursday, September 13, 2012

Keyboard Shortcuts on MAC Lion


Some Useful Keyboard Shortcuts on MAC Lion

Show Desktop    :    Five finger gesture Like a Zoom on trackpad.
Refresh Page    :     Command + R
Arrange Apps on Desktop :  Ctrl + Up Arrow Key
Switch Between Desktops :  Ctrl + Left and Right Arrow Keys
Print Screen on MAC: Command+Shift+3
Page Up and Page Down: Fn + Up Arrow And Fn + Down Arrow 



In php concatenate 2 string variables


There is only one string operator in PHP to concatenate string variables. And this operation is DOT (.). 

e.g., 

$fname = "Swapnil" 
$lname = "Goswami"

print "Hello". " " . $fname . " " . $lname

This would result into 

Hello Swapnil Goswami

Thursday, August 30, 2012

Microsoft Office Communicator (OCS) Client for MAC OS X


I've been search around to get a free Microsoft Office Communicator (OCS) Client for MAC OS X but I could not find it anywhere. 

Until recently Microsoft provided a single Messenger for Mac that was used for connecting to both - MSN Public IM Network as well as Private Office Communication Server (OCS). But with the release of Office 2011 Microsoft changed that altogether... Now there are 2 separate products - MSN Messenger which is still free but works only for Microsofts Public IM Network and Communicator for MAC which now comes bundled with Office 2011 for MAC and is not free.

So guys, forget getting it for free now, you are forced to buy a license for Office 2011 to get OCS now. 

Tuesday, August 28, 2012

Query to Find MySql DB and Table Sizes


To Find MySql DB Sizes

SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;

More Informative query is: 


SELECT IFNULL(B.engine,'Total') "Storage Engine", CONCAT(LPAD(REPLACE(FORMAT(
B.DSize/POWER(1024,pw),3),',',''),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') "Data Size",
CONCAT(LPAD(REPLACE(FORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Index Size",CONCAT(LPAD(REPLACE(FORMAT(B.TSize/
POWER(1024,pw),3),',',''),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') "Table Size"
FROM (SELECT engine,SUM(data_length) DSize,
SUM(index_length) ISize,SUM(data_length+index_length) TSize FROM information_schema.tablesWHERE table_schema NOT IN ('mysql','information_schema','performance_schema') AND
engine IS NOT NULL GROUP BY engine WITH ROLLUP) B,(SELECT 2 pw) A ORDER BY TSize;


To Find Individual MySql Table Sizes


SELECT TABLE_NAME, table_rows, data_length, index_length, 
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "schema_name";
Replace "schema_name" with your database name. 

Monday, August 27, 2012

Resetting macbook to factory settings without CD/DVD

Install or Reinstall Lion from Scratch

1. Backup your existing data. 
2. Restart and Hold down Command + R key until menu appears. 
3. Select Disk Utility from Menu and Continue. 
4. Once DU is loaded select your drive.
5. Check the status of your drive. If it does not say "Verified" that means your hard drive has already failed or it is about to fail. This is a permanent hardware failure and drive should be replaced at this time.
6. If you Drive was Verified, then click Erase from Menu. 
7. Select Format Type to MAC OS Extended and Erase. Wait until the process is completed.
8. Quit DU and come back to main menu. 
9. Select "Reinstall Lion" and click Install. This should start the Lion installation. Follow online instructions to complete the process.   

Friday, August 24, 2012

How to check if MySql table supports utf8 format


The best way to find if a MySql table is in UTF-8 format is to query the information schema. 

Use below query: 


select c.character_set_name from information_schema.tables as t,
     information_schema.collation_character_set_applicability as cwhere c.collation_name = t.table_collationand t.table_schema = "your_db"
and t.table_name = "table_name";


This would work with just mysql version >= 5.0.

Enjoy. 

Wednesday, August 22, 2012

Unable to connect - MFEWSErrorDomain error 56


Unable to connect - MFEWSErrorDomain error 56 using MAC Mail Client connecting to Exchange

I spent days troubleshooting my MAC mail client problem connecting to Exchange Server. 

Couple of things you should check for this are: 

1. You are able to connect to your Exchange Server. 
2. The Error above definitely means some incorrect settings. A common one is Mail > Preferences -> Accounts -> Advanced Look for Internal Server Path. If the Internal Server Path is set to EWS/webservices.aspx change it to to: EWS/exchange.asmx and retry. 
3.  Check Ports on which you are trying to connect to. 


Sunday, August 19, 2012

Find files created in last 24 hours in unix

This can be easily achieved by using the find command. 

find [path] [options]

See man page for detailed options of find command. 

find . -ctime -1 # finds files which are created in less then 1 day from currrent folder.
find . -ctime +2 # finds files which are created older then 2 days from currrent folder.


Enjoy.