求哔咔哔咔最新版官网apk

查询语句中包含中文时不能查询结果
编码问题! - ITeye问答
&&& 最近在做mysql查询时,发现一个很郁闷的问题:sql水土不服!
在公司内部做的mysql 查询,包含中文毫无问题。(mysql服务安装在公司,所用数据库编码设置成gbk,mysql安装设置编码为utf-8),项目运行一切OK。
但是 当把项目部署到客户的指定的服务器(可能是虚拟机)上 安装mysql服务 运行环境等,一切搞定后,发现只要有中文的查不出来数据。 没别的,肯定是编码问题,去修改安装配置文件,但是安装的是& mysql-5.1.53-win32, 结果目录下找不到my.ini 文件,找了一些ini 文件每一个包含default-character-set 属性设置这一项。
郁闷中,惆怅中,向各位同仁讨教,感激不尽。
问题补充:anyasir 写道没有可以加的,我干过
安装版或解压缩版,如果没有my.ini配置文件你就加个,设置好编码重启mysql服务
登录服务器show variables like '%char% 看是否起了作用额'
我添加这个文件后,启动mysql服务就报错了。
问题补充:wenchenyangailiuyan 写道给你上网查了点东西希望能帮到你
MYSQL数据库存在着编码问题,主要体现在数据库里汉字会出现乱码,WEB页面汉字显示不正常。
归结起来只有一个原因:会出现编码的地方存在编码不一致。
&&& WEB开发中:MYSQL编码主要会出现在五个地方:
&&&&&&& 1. mysql安装的默认编码(latin1)-在mysql.ini(mysql安装根目录下)中设置。[mysqld]选项,默认没有。添加即在最后一行加入default-character-set=utf8。
&&&&&& 2.mysql数据库的编码,原则上默认的编码是mysql安装的默认编码,也可以在建库时用语句来执行:create databasedbname default character set utf8;我这里是建立一个utf8编码的dbname数据库。
&&&&&&& 3.mysql数据表的编码,原则上默认是第二步建立的数据库的编码。提倡不要在creat table时加上编码
&&&&&&& 4.利用程序建立mysql连接时,连接字符串使用的编码。如jdbc,php mysql_connect(),这个地方必须是与你页面的编码一致。
&&&&&&& 5.WEB程序页面的编码,charset=utf8;与4必须一致。
&&&&& 除上面5个地方外,另有一个不是编码者所能控制的,那就是浏览用户的浏览器的编码,一般是自动选择,就不列入了。
&&&&&
&&&&&&& 上述五个地方,我所知道的保证不出现乱码的方法是:
&&& 1 无所谓,但是如果可以调整的话,可以设置成你所需要统一的一个编码,如utf8
&&& 2,3比较重要,我所理解的必须是一致。建议是在建库语句时带上编码,建表时就不指定编码了。
&&& 4是必须的,php下:$link = mysql_connect('localhost', 'root', '')&& or die('Could not connect: ' . mysql_error());
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& echo 'Connected successfully';
&&&&&&&&&&&&&&&&&&&&&&&&&&& mysql_select_db('wordpress') or die('Could not select database');
&&&&&&&&&&&&&&&&&&&&&&&&&&&&& mysql_query("set names utf8;");&& //这句
&&&&&&&&&&&&&&&&& 如利用PDO的话 $dbh = new PDO($dsn, $config['db']['username'], $config['db']['password']);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& $dbh-&exec('SET CHARACTER SET utf8');& //这句
&&&& 5在WEB页面中必须设置成上面的统一的编码。
请不要结束,继续往下看:上述方法中必须统一是统一的编码,我使用的是utf8,为什么使用utf8是我正要说的。
&&&&&&&&&&&&&& 备注说明
&&&&&&&&&&&&&&&& 1、统一使用GBK编码的话,大多数时候是不会出问题。但是如果遇到·这种字符,这个字段后的所有汉字都回出现乱码。这在oracle中同样存在。因为mysql,oracle的默认编码似乎都是(mysql-latin1亦是)iso-8559-1,对某些特殊字符会出现乱码。因此建议使用utf8。使用utf8亦是我以前排斥的,但是在hiu遇到疯狂的小覃后改变了我的观点,utf8有利于建设网站的其它版本,比如英文版...,而且设置似乎也没有丝毫麻烦。。。
&&&&&&&&&&&&&&&& 2、在上述的一个过程中,使用了mysql的gui管理工具(除去web形式的phpadmin)的,如果你出现了乱码问题,那是显然的。比如sqlyog, mysql 的 mysql administrator是有默认编码的。所以在建库,建表的时候尽量使用语句在工具里来执行,而不是直接右键来createdatabase。phpadmin不存在这个问题(它是web程序)。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/twosecond/archive//4289052.aspx
问题补充:anyasir 写道直接加my.ini文件,其他ini文件54
谢谢你
54是什么意思? 不好意思真不懂。
问题补充:anyasir 写道贴下你加的文件
不好意思 这虚拟机太慢了
下面是my.ini 文件:
# Example MySQL config file for large systems.
# This is for a large system with memory = 512M where the system runs mainly
# You can copy this file to
# /f to set global options,
# mysql-data-f to set server-specific options (in this
# installation this directory is C:\mysql\data) or
# ~/.my.cnf to set user-specific options.
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
#password = your_password
= /tmp/mysql.sock
default-character-set=gbk
# Here follows entries for some specific programs
# The MySQL server
basedir=F:\\tools\\mysql-5.1.44-win32
datadir=F:\\tools\\mysql-5.1.44-win32\\data
= /tmp/mysql.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
bind-address = 192.168.101.200
default-character-set=gbk
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
# To configure this host as a replication slave, you can choose between
# two methods :
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
the syntax is:
CHANGE MASTER TO MASTER_HOST=&host&, MASTER_PORT=&port&,
MASTER_USER=&user&, MASTER_PASSWORD=&password& ;
where you replace &host&, &user&, &password& by quoted strings and
&port& by the master's port number (3306 by default).
CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
MASTER_USER='joe', MASTER_PASSWORD='secret';
# 2) Set the variables below. However, in case you choose this method, then
start replication for the first time (even unsuccessfully, for example
if you mistyped the password in master-password and the slave fails to
connect), the slave will create
file, and any later
change in this file to the variables' values below will be ignored and
overridden by the content of
file, unless you shutdown
the slave server,
and restart the slaver server.
For that reason, you may want to leave the lines below untouched
(commented) and instead use CHANGE MASTER TO (see above)
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id
# The replication master for this slave - required
#master-host
&hostname&
# The username the slave will use for authentication when connecting
# to the master - required
#master-user
&username&
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =
&password&
# The port the master is listening on.
# optional - defaults to 3306
#master-port
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Point the following paths to different dedicated disks
#log-update
= /path-to-dedicated-directory/hostname
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\mysql\data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
max_allowed_packet = 16M
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
问题补充:anyasir 写道其他文件动过没?如果其他文件没动过,加这句到my.ini试试
default-storage-engine = INNODB 加在[mysqld]下
数据库优化我不懂 看不出你这个文件有什么问题
只是没有设置引擎 default-storage-engine = INNODB 没记错的话这个是管事务的
你好,其他的文件都没动,
按上面修改之后,加载仍然报错。错如如下:
错误1067:在本地计算机无法启动mysql,进程意外终止。
问题补充:anyasir 写道[client]
default-character-set = GBK
[mysql]
default-character-set = GBK
[mysqld]
port = 3306
character-set-server = GBK
default-storage-engine = INNODB
max_connections = 100
max_allowed_packet = 16M&
basedir=D:/services/mysql
datadir=D:/services/mysql/data
这个是我本地的一个解压缩版的,本来没有my.ini文件,我自己加上去的
这个文件没有调优什么的,我不懂那个,你改下路径放入你的mysql根目录,自己把原来的备份先,我这个不一定能搞定,只能试试
非常感谢你的拔刀相助,
呵呵 mysql启动成功了,但tomcat启动出问题了。
。。。。。
报错如下:
严重: The web application [/yahao] appears to have started a thread named [org.s
pringframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-8] but has failed
to stop it. This is very likely to create a memory leak.
13:16:49 org.apache.catalina.loader.WebappClassLoader clearReferencesTh
严重: The web application [/yahao] appears to have started a thread named [org.s
pringframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9] but has failed
to stop it. This is very likely to create a memory leak.
13:16:49 org.apache.catalina.loader.WebappClassLoader clearReferencesTh
严重: The web application [/yahao] appears to have started a thread named [org.s
pringframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-10] but has faile
d to stop it. This is very likely to create a memory leak.
问题补充:anyasir 写道[client]
default-character-set = GBK
[mysql]
default-character-set = GBK
[mysqld]
port = 3306
character-set-server = GBK
default-storage-engine = INNODB
max_connections = 100
max_allowed_packet = 16M&
basedir=D:/services/mysql
datadir=D:/services/mysql/data
这个是我本地的一个解压缩版的,本来没有my.ini文件,我自己加上去的
这个文件没有调优什么的,我不懂那个,你改下路径放入你的mysql根目录,自己把原来的备份先,我这个不一定能搞定,只能试试
刚才描述有点错误,tomcat能启动成功,访问8887端口下的tomcat没有问题,
但是访问项目就出问题了。
问题补充:anyasir 写道tomcat 启动日志多贴一点,光看这个只看出貌似定时任务有问题
仁兄 现在解决了。非常感谢!
做法是:从C盘里的WINDOW/下面copy的my.ini 文件到这个mysql下,再将编码设置给加上就没问题了。文件在最下面。我还想说的是:系统是server 2003的
mysql是以前同事在搭建php环境是用的mysql 貌似也是解压版的,难道my.ini 文件就跑到WINDOW下去了?
还有就是解压版和msi安装版本 有什么区别了? 解压版本是怎么将服务给装上的?(留言或者发短信 谢谢交流)
最后想说一句: 你很强!也很善良! 谢谢。
my.ini文件:
# Example MySQL config file for small systems.
# This is for a system with little memory (&= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
# You can copy this file to
# /f to set global options,
# mysql-data-f to set server-specific options (in this
# installation this directory is C:\mysql\data) or
# ~/.my.cnf to set user-specific options.
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
#password = your_password
= /tmp/mysql.sock
default-character-set = GBK
# Here follows entries for some specific programs
# The MySQL server
# set basedir to your installation path
basedir=F:/bbs/mysql-5.1.53-win32
# set datadir to the location of your data directory
datadir=F:/bbs/data
= /tmp/mysql.sock
skip-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
default-character-set = GBK
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#skip-networking
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
# binary logging format - mixed recommended
#binlog_format=mixed
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\mysql\data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
max_allowed_packet = 16M
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
采纳的答案
直接加my.ini文件,其他ini文件54
tomcat 启动日志多贴一点,光看这个只看出貌似定时任务有问题
[client]
default-character-set = GBK
[mysql]
default-character-set = GBK
[mysqld]
port = 3306
character-set-server = GBK
default-storage-engine = INNODB
max_connections = 100
max_allowed_packet = 16M&
basedir=D:/services/mysql
datadir=D:/services/mysql/data
这个是我本地的一个解压缩版的,本来没有my.ini文件,我自己加上去的
这个文件没有调优什么的,我不懂那个,你改下路径放入你的mysql根目录,自己把原来的备份先,我这个不一定能搞定,只能试试
其他文件动过没?如果其他文件没动过,加这句到my.ini试试
default-storage-engine = INNODB 加在[mysqld]下
数据库优化我不懂 看不出你这个文件有什么问题
只是没有设置引擎 default-storage-engine = INNODB 没记错的话这个是管事务的
无视的意思,其他的ini文件不要改,加个my.ini就可以
贴下你加的文件
没有可以加的,我干过
安装版或解压缩版,如果没有my.ini配置文件你就加个,设置好编码重启mysql服务
登录服务器show variables like '%char% 看是否起了作用额'
给你上网查了点东西希望能帮到你
MYSQL数据库存在着编码问题,主要体现在数据库里汉字会出现乱码,WEB页面汉字显示不正常。
归结起来只有一个原因:会出现编码的地方存在编码不一致。
&&& WEB开发中:MYSQL编码主要会出现在五个地方:
&&&&&&& 1. mysql安装的默认编码(latin1)-在mysql.ini(mysql安装根目录下)中设置。[mysqld]选项,默认没有。添加即在最后一行加入default-character-set=utf8。
&&&&&& 2.mysql数据库的编码,原则上默认的编码是mysql安装的默认编码,也可以在建库时用语句来执行:create databasedbname default character set utf8;我这里是建立一个utf8编码的dbname数据库。
&&&&&&& 3.mysql数据表的编码,原则上默认是第二步建立的数据库的编码。提倡不要在creat table时加上编码
&&&&&&& 4.利用程序建立mysql连接时,连接字符串使用的编码。如jdbc,php mysql_connect(),这个地方必须是与你页面的编码一致。
&&&&&&& 5.WEB程序页面的编码,charset=utf8;与4必须一致。
&&&&& 除上面5个地方外,另有一个不是编码者所能控制的,那就是浏览用户的浏览器的编码,一般是自动选择,就不列入了。
&&&&&
&&&&&&& 上述五个地方,我所知道的保证不出现乱码的方法是:
&&& 1 无所谓,但是如果可以调整的话,可以设置成你所需要统一的一个编码,如utf8
&&& 2,3比较重要,我所理解的必须是一致。建议是在建库语句时带上编码,建表时就不指定编码了。
&&& 4是必须的,php下:$link = mysql_connect('localhost', 'root', '')&& or die('Could not connect: ' . mysql_error());
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& echo 'Connected successfully';
&&&&&&&&&&&&&&&&&&&&&&&&&&& mysql_select_db('wordpress') or die('Could not select database');
&&&&&&&&&&&&&&&&&&&&&&&&&&&&& mysql_query("set names utf8;");&& //这句
&&&&&&&&&&&&&&&&& 如利用PDO的话 $dbh = new PDO($dsn, $config['db']['username'], $config['db']['password']);
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& $dbh-&exec('SET CHARACTER SET utf8');& //这句
&&&& 5在WEB页面中必须设置成上面的统一的编码。
请不要结束,继续往下看:上述方法中必须统一是统一的编码,我使用的是utf8,为什么使用utf8是我正要说的。
&&&&&&&&&&&&&& 备注说明
&&&&&&&&&&&&&&&& 1、统一使用GBK编码的话,大多数时候是不会出问题。但是如果遇到·这种字符,这个字段后的所有汉字都回出现乱码。这在oracle中同样存在。因为mysql,oracle的默认编码似乎都是(mysql-latin1亦是)iso-8559-1,对某些特殊字符会出现乱码。因此建议使用utf8。使用utf8亦是我以前排斥的,但是在hiu遇到疯狂的小覃后改变了我的观点,utf8有利于建设网站的其它版本,比如英文版...,而且设置似乎也没有丝毫麻烦。。。
&&&&&&&&&&&&&&&& 2、在上述的一个过程中,使用了mysql的gui管理工具(除去web形式的phpadmin)的,如果你出现了乱码问题,那是显然的。比如sqlyog, mysql 的 mysql administrator是有默认编码的。所以在建库,建表的时候尽量使用语句在工具里来执行,而不是直接右键来createdatabase。phpadmin不存在这个问题(它是web程序)。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/twosecond/archive//4289052.aspx
找这个SET&& NAMES&& gb2312
已解决问题
未解决问题mysql(6)
Mysql查找如何判断字段是否包含某个字符串
有这样一个需求,在Mysql字符串字段(权限)中,用户有多个不同的邮箱,分别被‘,’分开,现在要取出某个邮箱的所有成员列表。
假设有个表:
users(id int(6)
AUTO_INCREMENT,PRIMARY
(id),user_name VARCHAR(20)
NULL,emails
VARCHAR(50)
初始化表,并添加些记录。
users(user_name, emails) VALUES('小张',',,');
users(user_name, emails) VALUES('小王',',,');
Mysql 中有些字段是字符串类型的,如何查找其中包含某些字符的记录呢?
很简单可以用%来实现
users WHERE
emails like
但是这样子的话就会把也查出来了就不符合需求了
利用&字符串函数 find_in_set();
users WHERE
find_in_set('',
这样子就可以找到email字段里包含有的所有用户了
这样就能达到我们预期的效果,问题就解决了!
要注意的是:mysql字符串函数 find_in_set(str1,str2)函数是返回str2中str1所在的位置索引,str2必须以&,&分割开。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:45854次
排名:千里之外
原创:27篇
转载:33篇
(1)(6)(2)(2)(3)(2)(1)(2)(1)(2)(4)(1)(2)(1)(13)(4)(3)(1)(5)(4)如何在 MySQL 中判断中文字符? - 文章 - 伯乐在线
& 如何在 MySQL 中判断中文字符?
在生产环境中,经常会有这样的场景:获得中文数据。那问题就来了,怎么才能匹配出中文字符呢?
本文提供两种方法。
mysql& SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name
+-------------------------+------------------------------+
| protocol_version
| version_comment
| MySQL Community Server (GPL) |
| version_compile_machine | i386
| version_compile_os
| apple-darwin10.3.0
+-------------------------+------------------------------+
5 rows in set (0.00 sec)
1234567891011
mysql& SHOW VARIABLES LIKE "%version%";+-------------------------+------------------------------+| Variable_name&&&&&&&&&& | Value&&&&&&&&&&&&&&&&&&&&&&&&|+-------------------------+------------------------------+| protocol_version&&&&&&&&| 10&&&&&&&&&&&&&&&&&&&&&&&&&& || version&&&&&&&&&&&&&&&& | 5.1.73&&&&&&&&&&&&&&&&&&&&&& || version_comment&&&&&&&& | MySQL Community Server (GPL) || version_compile_machine | i386&&&&&&&&&&&&&&&&&&&&&&&& || version_compile_os&&&&&&| apple-darwin10.3.0&&&&&&&&&& |+-------------------------+------------------------------+5 rows in set (0.00 sec)
2.2 创建测试表和插入测试数据
mysql -S /tmp/mysql_5173.sock -uroot -proot
mysql -S /tmp/mysql_5173.sock -uroot -proot
创建测试表和插入测试数据。
mysql& USE
Database changed
mysql& CREATE TABLE user
-& (name VARCHAR(20)
) DEFAULT CHARSET = utf8 ENGINE = INNODB;
Query OK, 0 rows affected (0.10 sec)
mysql& SHOW TABLE STATUS LIKE 'user' G;
*************************** 1. row ***************************
Name: user
Engine: InnoDB
Version: 10
Row_format: Compact
Avg_row_length: 8192
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 0
Auto_increment: NULL
Create_time:
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
1 row in set (0.00 sec)
No query specified
mysql& INSERT INTO user VALUES('robin');
Query OK, 1 row affected (0.01 sec)
mysql& INSERT INTO user VALUES('温国兵');
Query OK, 1 row affected (0.00 sec)
1234567891011121314151617181920212223242526272829303132333435363738
mysql& USE Database changed&mysql& CREATE TABLE user&&&&-& (name VARCHAR(20)&&&&-&&&) DEFAULT CHARSET = utf8 ENGINE = INNODB;Query OK, 0 rows affected (0.10 sec)&mysql& SHOW TABLE STATUS LIKE 'user' G;*************************** 1. row ***************************&&&&&&&&&& Name: user&&&&&&&& Engine: InnoDB&&&&&&&&Version: 10&&&& Row_format: Compact&&&&&&&&&& Rows: 2 Avg_row_length: 8192&&&&Data_length: 16384Max_data_length: 0&& Index_length: 0&&&&&&Data_free: 0 Auto_increment: NULL&&&&Create_time: 2015-01-16 18:01:36&&&&Update_time: NULL&&&& Check_time: NULL&&&&&&Collation: utf8_general_ci&&&&&& Checksum: NULL Create_options: &&&&&&&&Comment: 1 row in set (0.00 sec)&ERROR: No query specified&mysql& INSERT INTO user VALUES('robin');Query OK, 1 row affected (0.01 sec)&mysql& INSERT INTO user VALUES('温国兵');Query OK, 1 row affected (0.00 sec)
3.1 方法一 正则表达式
mysql& SELECT * FROM user G;
*************************** 1. row ***************************
name: robin
*************************** 2. row ***************************
name: 温国兵
2 rows in set (0.00 sec)
mysql& SELECT name,
CASE name REGEXP "[u0391-uFFE5]"
WHEN 1 THEN "不是中文字符"
ELSE "是中文字符"
END AS "判断是否是中文字符"
+-----------+-----------------------------+
| 判断是否是中文字符 |
+-----------+-----------------------------+
| 不是中文字符
| 温国兵 | 是中文字符
+-----------+-----------------------------+
2 rows in set (0.00 sec)
mysql& SELECT name FROM user WHERE NOT (name REGEXP "[u0391-uFFE5]");
+-----------+
+-----------+
| 温国兵 |
+-----------+
1 row in set (0.00 sec)
12345678910111213141516171819202122232425262728
mysql& SELECT * FROM user G;*************************** 1. row ***************************name: robin*************************** 2. row ***************************name: 温国兵2 rows in set (0.00 sec)&mysql& SELECT name,&&&&-&&&&& CASE name REGEXP "[u0391-uFFE5]"&&&&-&&&&&&&&& WHEN 1 THEN "不是中文字符"&&&&-&&&&&&&&& ELSE "是中文字符"&&&&-&&&&& END AS "判断是否是中文字符"&&&&-& FROM user;+-----------+-----------------------------+| name&&&&&&| 判断是否是中文字符 |+-----------+-----------------------------+| robin&&&& | 不是中文字符&&&&&&&&&&|| 温国兵 | 是中文字符&&&&&&&&&&&& |+-----------+-----------------------------+2 rows in set (0.00 sec)&mysql& SELECT name FROM user WHERE NOT (name REGEXP "[u0391-uFFE5]");+-----------+| name&&&&&&|+-----------+| 温国兵 |+-----------+1 row in set (0.00 sec)
3.2 方法二 length() 和 char_length()
mysql& SELECT name, length(name), char_length(name) FROM
+-----------+--------------+-------------------+
| length(name) | char_length(name) |
+-----------+--------------+-------------------+
| 温国兵 |
+-----------+--------------+-------------------+
2 rows in set (0.00 sec)
mysql& SELECT name FROM user WHERE length(name)
char_length(name);
+-----------+
+-----------+
| 温国兵 |
+-----------+
1 row in set (0.00 sec)
12345678910111213141516
mysql& SELECT name, length(name), char_length(name) FROM user;+-----------+--------------+-------------------+| name&&&&&&| length(name) | char_length(name) |+-----------+--------------+-------------------+| robin&&&& |&&&&&&&&&&&&5 |&&&&&&&&&&&&&&&& 5 || 温国兵 |&&&&&&&&&& 20 |&&&&&&&&&&&&&&&& 9 |+-----------+--------------+-------------------+2 rows in set (0.00 sec)&mysql& SELECT name FROM user WHERE length(name)&&char_length(name);+-----------+| name&&&&&&|+-----------+| 温国兵 |+-----------+1 row in set (0.00 sec)
方法一中,[u0391-uFFE5] 匹配中文以外的字符。
方法二中,当字符集为UTF-8,并且字符为中文时,length() 和 char_length() 两个方法返回的结果不相同。
参考官方文档:
Return the length of a string in bytes
Returns the length of the string str, measured in bytes. A multibyte character counts as multiple bytes. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
CHAR_LENGTH()
Return number of characters in argument
Returns the length of the string str, measured in characters. A multibyte character counts as a single character. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
可能感兴趣的话题
关于伯乐在线博客
在这个信息爆炸的时代,人们已然被大量、快速并且简短的信息所包围。然而,我们相信:过多“快餐”式的阅读只会令人“虚胖”,缺乏实质的内涵。伯乐在线内容团队正试图以我们微薄的力量,把优秀的原创文章和译文分享给读者,为“快餐”添加一些“营养”元素。
新浪微博:
推荐微信号
(加好友请注明来意)
– 好的话题、有启发的回复、值得信赖的圈子
– 分享和发现有价值的内容与观点
– 为IT单身男女服务的征婚传播平台
– 优秀的工具资源导航
– 翻译传播优秀的外文文章
– 国内外的精选文章
– UI,网页,交互和用户体验
– 专注iOS技术分享
– 专注Android技术分享
– JavaScript, HTML5, CSS
– 专注Java技术分享
– 专注Python技术分享
& 2017 伯乐在线

我要回帖

更多关于 哔哩哔哩动画 的文章

 

随机推荐