filer.store.mysql: Use utf8mb4 instead of 3 byte UTF8 (#4094)

This commit is contained in:
CommanderRoot 2023-01-01 14:07:53 +01:00 committed by GitHub
parent c2280e94cf
commit c7c9d22f37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 29 deletions

View file

@ -3,10 +3,10 @@ CREATE USER IF NOT EXISTS 'seaweedfs'@'%' IDENTIFIED BY 'secret';
GRANT ALL PRIVILEGES ON seaweedfs.* TO 'seaweedfs'@'%'; GRANT ALL PRIVILEGES ON seaweedfs.* TO 'seaweedfs'@'%';
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
USE seaweedfs; USE seaweedfs;
CREATE TABLE IF NOT EXISTS filemeta ( CREATE TABLE IF NOT EXISTS `filemeta` (
dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field', `dirhash` BIGINT NOT NULL COMMENT 'first 64 bits of MD5 hash value of directory field',
name VARCHAR(1000) COMMENT 'directory or file name', `name` VARCHAR(766) NOT NULL COMMENT 'directory or file name',
directory TEXT COMMENT 'full path to parent directory', `directory` TEXT NOT NULL COMMENT 'full path to parent directory',
meta LONGBLOB, `meta` LONGBLOB,
PRIMARY KEY (dirhash, name) PRIMARY KEY (`dirhash`, `name`)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

View file

@ -14,13 +14,13 @@ with ENV.
A running MySQL-compatible database is expected by default, as specified in the `values.yaml` at `filer.extraEnvironmentVars`. A running MySQL-compatible database is expected by default, as specified in the `values.yaml` at `filer.extraEnvironmentVars`.
This database should be pre-configured and initialized by running: This database should be pre-configured and initialized by running:
```sql ```sql
CREATE TABLE IF NOT EXISTS filemeta ( CREATE TABLE IF NOT EXISTS `filemeta` (
dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field', `dirhash` BIGINT NOT NULL COMMENT 'first 64 bits of MD5 hash value of directory field',
name VARCHAR(1000) BINARY COMMENT 'directory or file name', `name` VARCHAR(766) NOT NULL COMMENT 'directory or file name',
directory TEXT BINARY COMMENT 'full path to parent directory', `directory` TEXT NOT NULL COMMENT 'full path to parent directory',
meta LONGBLOB, `meta` LONGBLOB,
PRIMARY KEY (dirhash, name) PRIMARY KEY (`dirhash`, `name`)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
``` ```
Alternative database can also be configured (e.g. leveldb) following the instructions at `filer.extraEnvironmentVars`. Alternative database can also be configured (e.g. leveldb) following the instructions at `filer.extraEnvironmentVars`.

View file

@ -41,13 +41,13 @@ enabled = false
dbFile = "./filer.db" # sqlite db file dbFile = "./filer.db" # sqlite db file
[mysql] # or memsql, tidb [mysql] # or memsql, tidb
# CREATE TABLE IF NOT EXISTS filemeta ( # CREATE TABLE IF NOT EXISTS `filemeta` (
# dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field', # `dirhash` BIGINT NOT NULL COMMENT 'first 64 bits of MD5 hash value of directory field',
# name VARCHAR(1000) BINARY COMMENT 'directory or file name', # `name` VARCHAR(766) NOT NULL COMMENT 'directory or file name',
# directory TEXT BINARY COMMENT 'full path to parent directory', # `directory` TEXT NOT NULL COMMENT 'full path to parent directory',
# meta LONGBLOB, # `meta` LONGBLOB,
# PRIMARY KEY (dirhash, name) # PRIMARY KEY (`dirhash`, `name`)
# ) DEFAULT CHARSET=utf8; # ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
enabled = false enabled = false
hostname = "localhost" hostname = "localhost"
@ -67,12 +67,12 @@ upsertQuery = """INSERT INTO `%s` (`dirhash`,`name`,`directory`,`meta`) VALUES (
enabled = false enabled = false
createTable = """ createTable = """
CREATE TABLE IF NOT EXISTS `%s` ( CREATE TABLE IF NOT EXISTS `%s` (
dirhash BIGINT, `dirhash` BIGINT NOT NULL,
name VARCHAR(1000) BINARY, `name` VARCHAR(766) NOT NULL,
directory TEXT BINARY, `directory` TEXT NOT NULL,
meta LONGBLOB, `meta` LONGBLOB,
PRIMARY KEY (dirhash, name) PRIMARY KEY (`dirhash`, `name`)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
""" """
hostname = "localhost" hostname = "localhost"
port = 3306 port = 3306

View file

@ -13,7 +13,7 @@ import (
) )
const ( const (
CONNECTION_URL_PATTERN = "%s:%s@tcp(%s:%d)/%s?charset=utf8" CONNECTION_URL_PATTERN = "%s:%s@tcp(%s:%d)/%s?collation=utf8mb4_bin"
) )
func init() { func init() {

View file

@ -15,7 +15,7 @@ import (
) )
const ( const (
CONNECTION_URL_PATTERN = "%s:%s@tcp(%s:%d)/%s?charset=utf8" CONNECTION_URL_PATTERN = "%s:%s@tcp(%s:%d)/%s?collation=utf8mb4_bin"
) )
var _ filer.BucketAware = (*MysqlStore2)(nil) var _ filer.BucketAware = (*MysqlStore2)(nil)