Welcome to the MariaDB monitor.
Your MariaDB connection id is 2
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| Variable_name
+--------------------------+----------------------------+
| character_set_client
| character_set_connection | utf8
| character_set_database
| character_set_filesystem | binary
| character_set_results
| character_set_server
| character_set_system
| character_sets_dir
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> SHOW VARIABLES LIKE 'collation%';
+----------------------+-------------------+
| Variable_name
+----------------------+-------------------+
| collation_connection | utf8_general_ci
| collation_database
| collation_server
+----------------------+-------------------+
3 rows in set (0.00 sec)
1. SET NAMES 'utf8';
2. 创建数据库是指定编码
MariaDB [(none)]> CREATE DATABASE foo CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> USE foo;
Database changed
MariaDB [foo]> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| Variable_name
+--------------------------+----------------------------+
| character_set_client
| character_set_connection | utf8
| character_set_database
| character_set_filesystem | binary
| character_set_results
| character_set_server
| character_set_system
| character_sets_dir
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
MariaDB [foo]> SHOW VARIABLES LIKE 'collation%';
+----------------------+-------------------+
| Variable_name
+----------------------+-------------------+
| collation_connection | utf8_general_ci
| collation_database
| collation_server
+----------------------+-------------------+
3 rows in set (0.00 sec)
示例:
CREATE TABLE mytable
(
columnn1 INT,
columnn2 VARCHAR(10)
)DEFAULT
CHARACTER
SET
CREATE OR REPLACE TABLE mytable
(columnn1 INT,
columnn2 VARCHAR(10),
column3 VARCHAR(10)
)DEFAULT
CHARACTER
SET
SELECT * FROM customers ORDER BY lastname,
firstname
ALTER DATABASE database_name CHARACTER SET utf8;
ALTER TABLE table_name CHARACTER SET utf8;
MariaDB [foo]> DESC hello;
+-------+----------+------+-----+---------+-------+
| Field | Type
+-------+----------+------+-----+---------+-------+
| id
| name
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
MariaDB [foo]> ALTER TABLE hello MODIFY name char(50) CHARACTER SET utf8;
Query OK, 0 rows affected (0.00 sec)
Records: 0
Welcome to the MariaDB monitor.
Your MariaDB connection id is 2
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database
| collation_server
+----------------------+-----------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| Variable_name
+--------------------------+----------------------------+
| character_set_client
| character_set_connection | utf8
| character_set_database
| character_set_filesystem | binary
| character_set_results
| character_set_server
| character_set_system
| character_sets_dir
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
init_connect =
init_connect =
character_set_server =
collation_server =
init_connect =
init_connect =
character_set_server =
collation_server =