From c7c9d22f37de989b20fd06aaf9c6ea1411028834 Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Sun, 1 Jan 2023 14:07:53 +0100 Subject: [PATCH] filer.store.mysql: Use utf8mb4 instead of 3 byte UTF8 (#4094) --- docker/seaweedfs.sql | 14 +++++++------- k8s/helm_charts2/README.md | 14 +++++++------- weed/command/scaffold/filer.toml | 26 +++++++++++++------------- weed/filer/mysql/mysql_store.go | 2 +- weed/filer/mysql2/mysql2_store.go | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docker/seaweedfs.sql b/docker/seaweedfs.sql index a27eb7081..c9974e0e6 100644 --- a/docker/seaweedfs.sql +++ b/docker/seaweedfs.sql @@ -3,10 +3,10 @@ CREATE USER IF NOT EXISTS 'seaweedfs'@'%' IDENTIFIED BY 'secret'; GRANT ALL PRIVILEGES ON seaweedfs.* TO 'seaweedfs'@'%'; FLUSH PRIVILEGES; USE seaweedfs; -CREATE TABLE IF NOT EXISTS filemeta ( - dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field', - name VARCHAR(1000) COMMENT 'directory or file name', - directory TEXT COMMENT 'full path to parent directory', - meta LONGBLOB, - PRIMARY KEY (dirhash, name) -) DEFAULT CHARSET=utf8; \ No newline at end of file +CREATE TABLE IF NOT EXISTS `filemeta` ( + `dirhash` BIGINT NOT NULL COMMENT 'first 64 bits of MD5 hash value of directory field', + `name` VARCHAR(766) NOT NULL COMMENT 'directory or file name', + `directory` TEXT NOT NULL COMMENT 'full path to parent directory', + `meta` LONGBLOB, + PRIMARY KEY (`dirhash`, `name`) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; \ No newline at end of file diff --git a/k8s/helm_charts2/README.md b/k8s/helm_charts2/README.md index 715dcffa7..a510b02ca 100644 --- a/k8s/helm_charts2/README.md +++ b/k8s/helm_charts2/README.md @@ -14,13 +14,13 @@ with ENV. 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: ```sql -CREATE TABLE IF NOT EXISTS filemeta ( - dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field', - name VARCHAR(1000) BINARY COMMENT 'directory or file name', - directory TEXT BINARY COMMENT 'full path to parent directory', - meta LONGBLOB, - PRIMARY KEY (dirhash, name) -) DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `filemeta` ( + `dirhash` BIGINT NOT NULL COMMENT 'first 64 bits of MD5 hash value of directory field', + `name` VARCHAR(766) NOT NULL COMMENT 'directory or file name', + `directory` TEXT NOT NULL COMMENT 'full path to parent directory', + `meta` LONGBLOB, + PRIMARY KEY (`dirhash`, `name`) +) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; ``` Alternative database can also be configured (e.g. leveldb) following the instructions at `filer.extraEnvironmentVars`. diff --git a/weed/command/scaffold/filer.toml b/weed/command/scaffold/filer.toml index 423d0914e..88f9be2a6 100644 --- a/weed/command/scaffold/filer.toml +++ b/weed/command/scaffold/filer.toml @@ -41,13 +41,13 @@ enabled = false dbFile = "./filer.db" # sqlite db file [mysql] # or memsql, tidb -# CREATE TABLE IF NOT EXISTS filemeta ( -# dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field', -# name VARCHAR(1000) BINARY COMMENT 'directory or file name', -# directory TEXT BINARY COMMENT 'full path to parent directory', -# meta LONGBLOB, -# PRIMARY KEY (dirhash, name) -# ) DEFAULT CHARSET=utf8; +# CREATE TABLE IF NOT EXISTS `filemeta` ( +# `dirhash` BIGINT NOT NULL COMMENT 'first 64 bits of MD5 hash value of directory field', +# `name` VARCHAR(766) NOT NULL COMMENT 'directory or file name', +# `directory` TEXT NOT NULL COMMENT 'full path to parent directory', +# `meta` LONGBLOB, +# PRIMARY KEY (`dirhash`, `name`) +# ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; enabled = false hostname = "localhost" @@ -67,12 +67,12 @@ upsertQuery = """INSERT INTO `%s` (`dirhash`,`name`,`directory`,`meta`) VALUES ( enabled = false createTable = """ CREATE TABLE IF NOT EXISTS `%s` ( - dirhash BIGINT, - name VARCHAR(1000) BINARY, - directory TEXT BINARY, - meta LONGBLOB, - PRIMARY KEY (dirhash, name) - ) DEFAULT CHARSET=utf8; + `dirhash` BIGINT NOT NULL, + `name` VARCHAR(766) NOT NULL, + `directory` TEXT NOT NULL, + `meta` LONGBLOB, + PRIMARY KEY (`dirhash`, `name`) + ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; """ hostname = "localhost" port = 3306 diff --git a/weed/filer/mysql/mysql_store.go b/weed/filer/mysql/mysql_store.go index ea40373d9..14566d49b 100644 --- a/weed/filer/mysql/mysql_store.go +++ b/weed/filer/mysql/mysql_store.go @@ -13,7 +13,7 @@ import ( ) 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() { diff --git a/weed/filer/mysql2/mysql2_store.go b/weed/filer/mysql2/mysql2_store.go index 7008de171..acf621a00 100644 --- a/weed/filer/mysql2/mysql2_store.go +++ b/weed/filer/mysql2/mysql2_store.go @@ -15,7 +15,7 @@ import ( ) 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)