A small library for handing MySQL UTF8 filename encoding
Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
mysqlUTF8.go
mysqlUTF8_test.go

README.md

mysqlUTF8

Build Status Coverage GoDoc license

mysqlUTF8 is a small library for handling MySQL UTF8 filename encoding. Database and table names with special characters are encoded on disk as detailed in the MySQL documentation.

For example if you create a database named Ω the directory @7P will be created in the MySQL data directory. The NeedsEncoding() function determines if a string requires encoding and the EncodeFilename() function will return an encoded string.

func NeedsEncoding(s string) bool

fmt.Println(mysqlUTF8.NeedsEncoding("test"))
fmt.Println(mysqlUTF8.NeedsEncoding("¿"))
fmt.Println(mysqlUTF8.NeedsEncoding("¢ent"))

// Output:
// false
// true
// true
func EncodeFilename(s string) string

fmt.Println(mysqlUTF8.EncodeFilename("test"))
fmt.Println(mysqlUTF8.EncodeFilename("¿"))
fmt.Println(mysqlUTF8.EncodeFilename("(╯°□°)╯︵ ┻━┻"))

// Output:
// test
// @00bf
// @0028@256f@00b0@25a1@00b0@0029@256f@fe35@0020@253b@2501@253b