这是有关Swisscom Cloud MariaDB服务的澄清请求。这与通用MariaDB default charactersets无关。
character_set_server
定义为什么。latin1
,我想知道是否可以更改此默认值(utf-8
或更准确utf8mb4
,因为它是debian mariadb package
)。 我的问题的主要原因是我在创建可以轻松重新导入的备份时遇到问题,与通过{mysqldump ... -r backup.sql
进行提取相比,我获得了大小不同的大小输出1}}。
答案 0 :(得分:2)
我没有使用Sequel Pro
工具。
旧版MariaDB / Galera群集在您未设置时使用latin1
作为默认字符集。此默认设置来自上游MariaDB开发人员。大多数开发人员和DBA都不喜欢这个决定。
以下是CREATE TABLE
语法(请参阅COLLATE
和CHARACTER SET
):
CREATE TABLE tbl_name (column_list)
[[DEFAULT] CHARACTER SET charset_name]
[COLLATE collation_name]]
服务器设置(此语句可以执行每个客户,无需管理员权限):
MariaDB [(none)]> show global variables like 'character_set%';
+--------------------------+-------------------------------------+
| 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/mariadb-galera/charsets/ |
+--------------------------+-------------------------------------+
8 rows in set (0.00 sec)
如果您仍然使用旧版MariaDB,请
我们为您准备了全新的MariaDB服务。它来了 有许多改进(例如MariaDB版本10),我们建议 尽快升级。
创建了此分步指南Aug 16, 2017。
新群集使用更好的默认设置:
MariaDB [(none)]> show global variables like 'character_set%';
+--------------------------+------------------------------------------------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /var/vcap/data/packages/mariadb/95a1896c4bcdccb4e1abd81b7d00eb33aedb0da0/share/charsets/ |
+--------------------------+------------------------------------------------------------------------------------------+
8 rows in set (0.01 sec)
如果您希望在将数据导入新群集之前更改字符集和排序规则。
ALTER TABLE tbl_name
[[DEFAULT] CHARACTER SET charset_name]
[COLLATE collation_name]
我们做了很多次。请记住,你不应该用>这样做。 20000条记录。
请同时查看我们的documentation for MariaDB
如有需要,请联系Swisscom Application Cloud支持 发出长时间运行的DDL更改(例如
ALTER TABLE
与thousends 记录)。长时间运行的DDL会导致所有客户中断 集群。
答案 1 :(得分:1)
这是为了演示两个不同的ALTERs
;一个人没有用;一个人做你想做的事:
- 尝试'错误'更改:
DROP TABLE IF EXISTS atc;
CREATE TABLE atc ( c VARCHAR(11)) CHARACTER SET latin1 ;
INSERT INTO atc (c) VALUES ('ÃÔäô');
SHOW CREATE TABLE atc\G
SELECT c, HEX(c) FROM atc; -- note the latin1 encoding
ALTER TABLE atc CHARACTER SET utf8;
SHOW CREATE TABLE atc\G -- the column stays latin1, overriding the table
SELECT c, HEX(c) FROM atc; -- still latin1 encoding
mysql>
mysql> -- Try the 'wrong' ALTER:
mysql>
mysql> DROP TABLE IF EXISTS atc;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE atc ( c VARCHAR(11)) CHARACTER SET latin1 ;
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO atc (c) VALUES ('ÃÔäô');
Query OK, 1 row affected (0.00 sec)
mysql> SHOW CREATE TABLE atc\G
*************************** 1. row ***************************
Table: atc
Create Table: CREATE TABLE `atc` (
`c` varchar(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> SELECT c, HEX(c) FROM atc; -- note the latin1 encoding
+----------+----------+
| c | HEX(c) |
+----------+----------+
| ÃÔäô | C3D4E4F4 |
+----------+----------+
1 row in set (0.00 sec)
mysql> ALTER TABLE atc CHARACTER SET utf8;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SHOW CREATE TABLE atc\G -- the column stays latin1, overriding the table
*************************** 1. row ***************************
Table: atc
Create Table: CREATE TABLE `atc` (
`c` varchar(11) CHARACTER SET latin1 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> SELECT c, HEX(c) FROM atc; -- still latin1 encoding
+----------+----------+
| c | HEX(c) |
+----------+----------+
| ÃÔäô | C3D4E4F4 |
+----------+----------+
1 row in set (0.00 sec)
- 尝试'正确'的方式:
DROP TABLE IF EXISTS atc;
CREATE TABLE atc ( c VARCHAR(11)) CHARACTER SET latin1 ;
INSERT INTO atc (c) VALUES ('ÃÔäô');
SHOW CREATE TABLE atc\G
SELECT c, HEX(c) FROM atc; -- note the latin1 encoding
ALTER TABLE atc CONVERT TO CHARACTER SET utf8;
SHOW CREATE TABLE atc\G -- column and table are utf8
SELECT c, HEX(c) FROM atc; -- now utf8
mysql>
mysql> -- Try the 'right' way:
mysql>
mysql> DROP TABLE IF EXISTS atc;
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE atc ( c VARCHAR(11)) CHARACTER SET latin1 ;
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO atc (c) VALUES ('ÃÔäô');
Query OK, 1 row affected (0.00 sec)
mysql> SHOW CREATE TABLE atc\G
*************************** 1. row ***************************
Table: atc
Create Table: CREATE TABLE `atc` (
`c` varchar(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> SELECT c, HEX(c) FROM atc; -- note the latin1 encoding
+----------+----------+
| c | HEX(c) |
+----------+----------+
| ÃÔäô | C3D4E4F4 |
+----------+----------+
1 row in set (0.00 sec)
mysql> ALTER TABLE atc CONVERT TO CHARACTER SET utf8;
Query OK, 1 row affected (0.03 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> SHOW CREATE TABLE atc\G -- column and table are utf8
*************************** 1. row ***************************
Table: atc
Create Table: CREATE TABLE `atc` (
`c` varchar(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
mysql> SELECT c, HEX(c) FROM atc; -- now utf8
+----------+------------------+
| c | HEX(c) |
+----------+------------------+
| ÃÔäô | C383C394C3A4C3B4 |
+----------+------------------+
1 row in set (0.00 sec)
mysql>