Databases Reference
In-Depth Information
mysql> SHOW VARIABLES LIKE 'c%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
...
+--------------------------+----------------------------+
14 rows in set (0.00 sec)
When you're creating a database, you can set the default character set and sort order
for the database and its tables. For example, if you want to use the latin1 character set
and the latin1_swedish_cs (case-sensitive) collation order, you would write:
mysql> CREATE DATABASE rose DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_cs;
Query OK, 1 row affected (0.00 sec)
As we've previously discussed, there's no need to do this if you've installed your MySQL
correctly for your language and region, and if you're not planning on internationalizing
your application. You can also control the character set and collation for individual
tables or columns, but we won't go into the detail of how to do that here.
Other Features
This section briefly describes other features of the MySQL CREATE TABLE statement. It
includes an example using the IF NOT EXISTS feature, and a list of advanced features
and where to find more about them in this topic.
You can use the IF NOT EXISTS keyword phrase when creating a table, and it works
much as it does for databases. Here's an example that won't report an error even when
the artist table exists:
mysql> CREATE TABLE IF NOT EXISTS artist (
-> artist_id SMALLINT(5) NOT NULL DEFAULT 0,
-> artist_name CHAR(128) DEFAULT NULL,
-> PRIMARY KEY (artist_id)
-> );
Query OK, 0 rows affected (0.00 sec)
It's actually hard to tell success from failure here: zero rows are affected whether or not
the table exists, and no warning is reported when the table does exist.
 
Search WWH ::




Custom Search