2020년에 작성한 노트를 옮겨 적은 것입니다.
inflection: string을 목적에 맞게 parsing해줌
Charset과 collation
문제: Schema 생성 시 에러 발생
Specified key was too long; max key length is 767 bytes
원인
MariaDB [bee_test]> select maxlen, character_set_name from information_schema.character_sets where character_set_name in('latin1', 'utf8', 'utf8mb4');
+--------+--------------------+
| maxlen | character_set_name |
+--------+--------------------+
| 1 | latin1 |
| 3 | utf8 |
| 4 | utf8mb4 |
+--------+--------------------+
해결
MariaDB [test]> status
--------------
mysql Ver 15.1 Distrib 10.1.44-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Connection id: 9
Current database: test
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 26 min 4 sec
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
define: {
charset: 'utf8',
collate: 'utf8_general_ci'
}
Collation
결국, MariaDB에서 VARCHAR는 몇 바이트까지 처리가능하지? 에 대한 의문에 대한 대답은
[NATIONAL] VARCHAR(M) [CHARACTER SET charset_name] [COLLATE collation_name]
A variable-length string. M represents the maximum column length in characters. The range of M is 0 to 65,532. The effective maximum length of a VARCHAR is subject to the maximum row size and the character set used. For example, utf8 characters can require up to three bytes per character, so a VARCHAR column that uses the utf8 character set can be declared to be a maximum of 21,844 characters.
MariaDB stores VARCHAR values as a one-byte or two-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A VARCHAR column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.