Bug #2151 USE db with non-default character set affects further CREATE DATABASEs
Description:
Why does character_set_database apply on the newly created database?
mysql> show variables like "%character_set%";
+--------------------------+------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------+
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_set_database | latin1 |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character-sets-dir | /usr/local/mysql-st-4.1.1/share/mysql/charsets |
| character_set_results | latin1 |
+--------------------------+------------------------------------------------+
7 rows in set (0.02 sec)
mysql> create database db1 default character set cp1251;
Query OK, 1 row affected (0.04 sec)
mysql> show create database db1;
+----------+----------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------+
| db1 | CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET cp1251 */ |
+----------+----------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> use db1;
Database changed
mysql> create database db2;
Query OK, 1 row affected (0.00 sec)
mysql> show create database db2;
+----------+----------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------+
| db2 | CREATE DATABASE `db2` /*!40100 DEFAULT CHARACTER SET cp1251 */ |
+----------+----------------------------------------------------------------+
1 row in set (0.00 sec)
But according MySQL manual character set of the db2 should be latin1:
MySQL chooses the database character set and database collation thus:
- If both CHARACTER SET X and COLLATE Y were specified, then character set X and collation Y.
- If CHARACTER SET X was specified without COLLATE, then character set X and its default collation.
- Otherwise, the server character set and server collation.
How to repeat:
Imagine, server is running latin1 by default.
create database db1 default character set cp1251;
use db1;
create database db2;
show create database db2;
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.056 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.