You are now browsing MySQL category.

October 7th, 2008 20:05   |   Category: MySQL

Database Management

Create a database: In the beginning the Universe was created.1


CREATE DATABASE db_name;

To see how database was created.


SHOW CREATE DATABASE db_name;

Set default charset:


ALTER DATABASE db_name DEFAULT CHARACTER SET latin5 COLLATE latin5_turkish_ci;
ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Listing running threads:


SHOW PROCESSLIST;

Table Management

Create a table:


CREATE TABLE table_name;

To see how table was created:

 
SHOW CREATE TABLE table_name;

Prints information about tables such as their versions, engines, collations:


SHOW TABLE STATUS;

Setting default character set and collation for a table:


ALTER TABLE table_name DEFAULT CHARACTER SET latin5 COLLATE latin5_turkish_ci;
ALTER TABLE table_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Changing a table’s character set including its columns’ character sets:


ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

Switching between engines:


ALTER TABLE table_name ENGINE = MyISAM;
ALTER TABLE table_name ENGINE = INNODB;

Let me know if I missed some other useful commands.

1 The Hitchhiker’s Guide to the Galaxy