Wednesday, April 7, 2010

mysql db name and table name limits

Database, table, and column names should not contain more the 64 characters
Database, table, and column names should not end with space characters.
Database, table, and column names should not contain slashes "\" ,"/" dots "." and commas ","

Identifier Maximum Length (characters) Database 64 Table 64 Column 64 Index 64 Constraint 64 Stored Function or Procedure 64 Trigger 64 View 64 Alias 256 (see exception following table) Compound Statement Label 16


Ref:
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
http://www.allinterview.com/showanswers/20054.html

Tuesday, April 6, 2010

Temporary tables in mysql

Question: What is temporary table and how to create temporary table in mysql

Answer:

Mysql Temporary tables are special kind tables it will be deleted when the script finishes its execution

To create temporary table use the command

CREATE TEMPORARY TABLE table_name (select mail_id,answer from interview_question)

If you want to delete the temporary table means

DROP TEMPORARY TABLE IF EXISTS table_name

How to create table same as another table?

Question: How to create table same as another table?(same structure)

Answer:Consider you are having a table named mysql_interview .

To make a same structured table use the following statment

$> CREATE TABLE your_new_tablename like mysql_interview

Monday, April 5, 2010

How to save query output as a table

Answer:

We need to use insert command followed by the select query

See the command

INSERT INTO mysql_interview SELECT * FROM source_table

what is name of mysql configuration file?

Answer

The configurations are stored in the my.cnf file

How to create a database in mysql

Answer

Use the following command

first login as mysql admin user

$>mysql -u root -p

Then

mysql> CREATE DATABASE mysqlinterview;

Now you have create a database name mysqlinterview

Thats all...

Sunday, April 4, 2010

How to create a user account in mysql

Answer

We can create an user account using the GRANT statement

Example:

$>mysql -u root -p
mysql> GRANT ALL ON mysqlquestions.* TO 'newusername'@'localhost' IDENTIFIED BY 'yourpassword'

Now you have created a user named "newusername" and given all access followed by the password "yourpassword"