mysql设置变量时何时可以使用表达示,何时可以使用M,G等单位

mysql设置变量时何时可以使用表达示,何时可以使用M,G等单位,第1张

在 *** 作符命令下不能使用 运算表达式,可以使用 M,G等单位

在mysql命令行中,可以使用 运算表达式, 不可以使用M,G等单位。

例: 在OS命令下:

[mysql@localhost mysql]$ mysql --max-allowed-packet=16M -u root -p123456

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with or \g.

Your MySQL connection id is 13

Server version: 5.6.23-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

[mysql@localhost mysql]$ mysql --max-allowed-packet=16*1024*1024 -u root -p123456

Unknown suffix '*' used for variable 'max_allowed_packet' (value '16*1024*1024')

Warning: option 'max_allowed_packet': unsigned value 0 adjusted to 4096

mysql: Error while setting value '16*1024*1024' to 'max_allowed_packet'

在mysql命令行下

mysql>set global max_allowed_packet=16M

ERROR 1232 (42000): Incorrect argument type to variable 'max_allowed_packet'

mysql>set global max_allowed_packet=16*1024*1024

Query OK, 0 rows affected (0.00 sec)

VARCHAR是MySQL中常用的数据类型,但其单位究竟是字符还是字节呢?

经过查阅,MySQL的 官方文档 给出了答案:

4.1及之后的版本,VARCHAR的单位是字符;4.1之前的版本,VARCHAR的单位是字节。(As of version 4.1 , MySQL interprets length specifications in character column definitions in character units . (Before MySQL 4.1, column lengths were interpreted in bytes .) This applies to CHAR, VARCHAR and the TEXT types.)

同时官方文档也提到,4.1及之后的版本以UTF-8作为预定义字符集。(VARCHAR is shorthand for CHARACTER VARYING. NATIONAL VARCHAR is the standard SQL way to define that a VARCHAR column should use some predefined character set. MySQL 4.1 and up uses UTF8 as this predefined character set .)

在 Go 语言中,是不能用 len 函数来统计字符串中的字符个数的,这是因为在 Go 中,字符串是以 UTF-8 为格式进行存储的,在字符串上调用 len 函数,取得的是字符串包含的 byte 的个数。

那么如何在Go语言中获取字符串中的字符个数呢?有下面几种方法:

测试发现速度最快的是 utf8.RuneCountInString()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7280645.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存