Showing posts with label alter database. Show all posts
Showing posts with label alter database. Show all posts

Thursday, 26 January 2012

MySQL db.opt File

When you create a database, you have to specify options such as the character set it will use:
 
mysql> create database andrew default charset utf8;
Query OK, 1 row affected (0.01 sec)
 
mysql>
 
These options are recorded in the db.opt file in the database directory:
 
UNIX > pwd
/usr/local/mysql/data/andrew
UNIX > cat db.opt
default-character-set=utf8
default-collation=utf8_general_ci
UNIX >
 
You can change them with the alter database command:
 
mysql> alter database andrew charset = dec8;
Query OK, 1 row affected (0.05 sec)
 
mysql>
 
... and the db.opt file will be updated:
 
UNIX > pwd
/usr/local/mysql/data/andrew
UNIX > cat db.opt
default-character-set=dec8
default-collation=dec8_swedish_ci
UNIX >

Friday, 13 January 2012

MySQL Character Set (part 2)

Go to part 1 

You can specify a database’s character set when you create it:
 
mysql> create database andrew
    -> default character set utf8;
Query OK, 1 row affected (0.00 sec)
 
mysql> show create database andrew;
+----------+-----------------------------------------------------------------+
| Database | Create Database                                                 |
+----------+-----------------------------------------------------------------+
| andrew   | CREATE DATABASE `andrew` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql>
 
... and you can alter it subsequently as follows:
 
mysql> alter database andrew charset = latin1;
Query OK, 1 row affected (0.00 sec)
 
mysql> show create database andrew;
+----------+-------------------------------------------------------------------+
| Database | Create Database                                                   |
+----------+-------------------------------------------------------------------+
| andrew   | CREATE DATABASE `andrew` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql>