Saturday, May 23, 2009

Make Money Online - Part Time Online Home Based Job




Hi ,

I have something interesting for you, RupeeMail!

It’s really amazing! You get paid to open & read the contents of RupeeMail. You receive promotional offers & special discounts in RupeeMail.

Interestingly RupeeMails will reach you based on the preference list you opted for.

Create your RupeeMail Account & refer your friends to earn launch referral bonus on every new registration.

Try this... Join Now!

RupeeMail, It pays



Monday, April 27, 2009

MySQL Table Types

MySQL supports several table types which allow to user to optimize the database. There are the following table types are available in MySQL:

1. ISAM
2. MyISAM
3. InnoDB
4. BerkeleyDB (BDB)
5. MERGE
6. HEAP

ISAM: ISAM had been deprecated and removed from version 5.x. All of it functionality integral replace by MyISAM. ISAM table has a hard size 4GB and is not portable.

MyISAM: MyISAM table type is default type when you make table. MyISAM table work very fast but not transaction-safe. The size of MyISAM table relies upon the operating system and the data file are portable from system to system. MyISAM tables support full-text indexing and searching feature.

InnoDB: InnoDB table are transaction safe, holds row-level locking and foreign keys are supported in this type of tables. The data file of InnoDB table can be stored in more than one file so the size of table depends on the disk space.

BDB: BDB is similar to InnoDB in transaction safe. It carries page level locking but data file are not portable.

MERGE: Merge table type is contributed to cover multiple MyISAM tables as a single table so it remove the size limitation from MyISAM tables.

HEAP: Heap table is stored in memory so it is the fastest one. Heap tables do not back up columns with AUTO_INCREMENT, BLOB and TEXT characteristics.

MySQL Download & Installation

Here is the different versions of MySQL, one you can download: http://dev.mysql.com/downloads/.

MySQL Installing on Windows:

This is very much easy to install MySQL on any version of windows:

* Simply download the installer package
* Unzip it anywhere
* Run setup.exe

ByDefault installer setup.exe will install everything under C:\mysql. If you are using windows NT then you will have to use mysqld-nt.exe instead of mysqld.exe. If all became well, you will see some messages about startup and InnoDB. If not, you may have a permissions issue. Make sure that the directory that holds your data is accessible to whatever user the database processes run under. When you install MySQL successfully, then you can see that MySQL not appear in start menu. Hence, if you tend to start the server by double clicking the mysqld executable, you should remember to halt the process by hand by using mysqladmin, Task List, Task Manager, or other Windows-specific means.

Installing MySQL on Linux/Unix

On the Linux/Unix operating system, you can install MySQL via RPM. MySQL AB makes the RPM, which is available for download on its web site is as follows:

* MySQL: This is the MySQL database server, that is manages databases and tables, processes SQL queries and controls user access.
* MySQL-devel: This is the Libraries and header files that come in ready to hand when compiling other programs that use MySQL.
* MySQL-bench: This is the Benchmark and performance testing tools for the MySQL database server.
* MySQL-client: This is the MySQL client programs, which connect and interact with the server.
* MySQL-shared: This is the Shared libraries for the MySQL client.

Now follow the following steps to proceed the installation:

1. Using root user login to the system.
2. Switch to the directory holding the RPM.
3. By executing the following command Install the MySQL database server.

[root@host]# rpm -i MySQL-5.0.9-0.i386.rpm

The Above command installing MySQL server, creating a user of MySQL, creating necessary configuration and starting MySQL server automatically. Which you can find all the MySQL related binaries in /usr/bin and /usr/sbin. All the tables and databases will be created in /var/lib/mysql directory.

4. This step is optional but it is used to install the remaining RPM in the same manner.
[root@host]# rpm -i MySQL-client-5.0.9-0.i386.rpm

[root@host]# rpm -i MySQL-devel-5.0.9-0.i386.rpm

[root@host]# rpm -i MySQL-shared-5.0.9-0.i386.rpm

[root@host]# rpm -i MySQL-bench-5.0.9-0.i386.rpm

Verifying Installation:

After MySQL has been installed, the server has been started and the base tables have been initialized successfully, you can verify whether all is working or not by some simple tests.

To check out server version, use mysqladmin binary. This would be available in /usr/bin on linux and in C:\mysql\bin on windows.
[root@host]# mysqladmin --version

It can show the following output on Linux.
mysqladmin Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386

If you do not find such message then there is some problem in your installation and you would need some help to fix it.

By using MySQL client, you can connect to your MySQL server using following mysql command.
[root@host]# mysql

Now you are connected to the MySQL server and you can execute all the SQL command at mysql> prompt as follows.
mysql> SHOW DATABASES;
+---------------+
| Database |
+---------------+
| mysql |
| test |
+---------------+
2 rows in set (0.13 sec)

After-installation Steps:

You need to set a root password as follows:
[root@host]# mysqladmin -u root password "new_password";

Now to make a connection to your MySQL server, use the following command:
[root@host]# mysql -u root -p

Enter password:*******

Unix users, put your MySQL directory in your PATH, For bash shell, it would be something as:
export PATH=$PATH:/usr/bin:/usr/sbin

If you want to run MySQL server at boot time then make certain you have following entry in /etc/rc.local file
/etc/init.d/mysqld start

Introduction to MySQL

MySQL is a database, it is a data storage area where small sections called TABLES. These tables having number of rows and columns. A database is a data storage feature where user can perform many action like: insert, update, delete, select, sort, arrange, and display information.

MySQL is a open source RDBMS (Relational Database Management System). It is very popular relational database Management System because it is free available for all platform. It is very much reliable and flexible. It provides a very high performance and it is multi threaded and multi user Relational Database management system.

The MySQL support almost all operating system like: Unix , window, and Mac. MySQL is used for the internet applications because it has high speed and highly secure. MySQL was developed to manage large volumes of data at very high speed for the web application.

Features of MySQL

* MySQL Handles large databases.
* MySQL has no memory leaks.
* The MySQL Passwords are secure since all password traffic when connecting to a server is encrypted.
* MySQL is very fast and more reliable for any type of application.
* It is very Lightweight application.
* MySQL command line tool is very powerful and can be used to run SQL queries against database.
* MySQL Supports indexing and binary objects.
* It is allow changes to structure of table while server is running.
* MySQL has a wide user base.
* It is a very fast thread-based memory allocation system.
*

MySQL Written in C and C++ language.
*

MySQL code is tested with different compilers.
*

MySQL is available as a separate program for use in a client/server network environment.
*

The MySQL available for the most Unix operating platform.
* MySQL are the available for window operating system window NT, window 95 ,and window 98.
* MySQL available for OS/2.
* Programming libraries for C, Python, PHP, Java , Delphi etc. are available to connect to MySQL database.

Advantages of MySQL

* Reliability and Performance
* Availability of Source
* Cross-Platform support
* Powerful Uncomplicated software

Features of MySQL 5

* Views: Views is created using columns from one or more tables. It is a virtual table which acts as a table but it contains no data. .
* Stored Procedures and Functions: In this feature it allows to user to plant business logic at database level.
* Triggers: The Triggers is used to create business logic whenever data is inserted, Deleted or updated in the table.

For more about MySQL: http://www.mysql.com/

Saturday, January 24, 2009

Difference between candidate key and primary key

Any attribute that is uniquely identify a row in a table is candidate key for the table. We select one of the candidate key as Primary key. All candidate keys which are not chosen as "primary key" are Alternate keys. The key which uniquely identify the rows of the table and which is made up of more than one attribute is called Composite key. Generally a candidate key becomes the primary key of the table. If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys.



MySQL Interview Questions Along with Answers

  1. How do you start and stop MySQL on Windows? - net start MySQL, net stop MySQL
  2. How do you start MySQL on Linux? - /etc/init.d/mysql start
  3. Explain the difference between mysql and mysqli interfaces in PHP? - mysqli is the object-oriented version of mysql library functions.
  4. What’s the default port for MySQL Server? - 3306
  5. What does tee command do in MySQL? - tee followed by a filename turns on MySQL logging to a specified file. It can be stopped by command notee.
  6. Can you save your connection settings to a conf file? - Yes, and name it ~/.my.conf. You might want to change the permissions on the file to 600, so that it’s not readable by others.
  7. How do you change a password for an existing user via mysqladmin? - mysqladmin -u root -p password "newpassword"
  8. Use mysqldump to create a copy of the database? - mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql
  9. Have you ever used MySQL Administrator and MySQL Query Browser? Describe the tasks you accomplished with these tools.
  10. What are some good ideas regarding user security in MySQL? - There is no user without a password. There is no user without a user name. There is no user whose Host column contains % (which here indicates that the user can log in from anywhere in the network or the Internet). There are as few users as possible (in the ideal case only root) who have unrestricted access.
  11. Explain the difference between MyISAM Static and MyISAM Dynamic. - In MyISAM static all the fields have fixed width. The Dynamic MyISAM table would include fields such as TEXT, BLOB, etc. to accommodate the data types with various lengths. MyISAM Static would be easier to restore in case of corruption, since even though you might lose some data, you know exactly where to look for the beginning of the next record.
  12. What does myisamchk do? - It compressed the MyISAM tables, which reduces their disk usage.
  13. Explain advantages of InnoDB over MyISAM? - Row-level locking, transactions, foreign key constraints and crash recovery.
  14. Explain advantages of MyISAM over InnoDB? - Much more conservative approach to disk space management - each MyISAM table is stored in a separate file, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace complexity.
  15. What are HEAP tables in MySQL? - HEAP tables are in-memory. They are usually used for high-speed temporary storage. No TEXT or BLOB fields are allowed within HEAP tables. You can only use the comparison operators = and <=>. HEAP tables do not support AUTO_INCREMENT. Indexes must be NOT NULL.
  16. How do you control the max size of a HEAP table? - MySQL config variable max_heap_table_size.
  17. What are CSV tables? - Those are the special tables, data for which is saved into comma-separated values files. They cannot be indexed.
  18. Explain federated tables. - Introduced in MySQL 5.0, federated tables allow access to the tables located on other databases on other servers.
  19. What is SERIAL data type in MySQL? - BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT
  20. What happens when the column is set to AUTO INCREMENT and you reach the maximum value for that table? - It stops incrementing. It does not overflow to 0 to prevent data losses, but further inserts are going to produce an error, since the key has been used already.
  21. Explain the difference between BOOL, TINYINT and BIT. - Prior to MySQL 5.0.3: those are all synonyms. After MySQL 5.0.3: BIT data type can store 8 bytes of data and should be used for binary data.
  22. Explain the difference between FLOAT, DOUBLE and REAL. - FLOATs store floating point numbers with 8 place accuracy and take up 4 bytes. DOUBLEs store floating point numbers with 16 place accuracy and take up 8 bytes. REAL is a synonym of FLOAT for now.
  23. If you specify the data type as DECIMAL (5,2), what’s the range of values that can go in this table? - 999.99 to -99.99. Note that with the negative number the minus sign is considered one of the digits.
  24. What happens if a table has one column defined as TIMESTAMP? - That field gets the current timestamp whenever the row gets altered.
  25. But what if you really want to store the timestamp data, such as the publication date of the article? - Create two columns of type TIMESTAMP and use the second one for your real data.
  26. Explain data type TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP - The column exhibits the same behavior as a single timestamp column in a table with no other timestamp columns.
  27. What does TIMESTAMP ON UPDATE CURRENT_TIMESTAMP data type do? - On initialization places a zero in that column, on future updates puts the current value of the timestamp in.
  28. Explain TIMESTAMP DEFAULT ‘2006:09:02 17:38:44′ ON UPDATE CURRENT_TIMESTAMP. - A default value is used on initialization, a current timestamp is inserted on update of the row.
  29. If I created a column with data type VARCHAR(3), what would I expect to see in MySQL table? - CHAR(3), since MySQL automatically adjusted the data type.