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 inset 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 MySQLcorrectly 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 FeaturesThis section briefly describes other features
of the MySQL CREATE TABLEstatement. It includes an example using the IF NOT EXISTS
feature, and a list of advanced features and whereto find more about them in this book.
You
can use the IF NOT EXISTSkeyword 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 (Share with your friends: