mysql5的字符集和sql mode问题
http://hi.baidu.com/gushu/blog/item/3e821c174eabec064a90a7d4.html
mysql5添加了一些新的功能的规则,其中对开源程序影响比较大的有两个,一个是4.0.12+开始的4层次字符集,一个是5.0.18开始的默认strict mode。
对于这两个问题,效率最好的解决方案,就是直接修改my.ini
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8
#这里改成utf-8
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION"
#这里改成=""
当你没有权限进行修改时,就只好在程序中判断了mysql5 新功能,必须在每次连接上数据库时进行设定。在使用了数据库抽象层的程序中修改起来也很简单:
if(mysql_get_server_info( $connect ) > '4.0.1')
{
mysql_query( "set names 'utf8'" , $connect );
}
if(mysql_get_server_info( $connect ) > '5.0.1')
{
mysql_query("SET sql_mode=''" , $connect );
}
相关文档:
1.字符串函数
长度与分析用
datalength(Char_expr) 返回字符串包含字符数,但不包含后面的空格
substring(expression,start,length) 不多说了,取子串
right(char_expr,int_expr) 返回字符串右边int_expr个字符
字符操作类
upper(char_expr) 转为大写
lower(char_expr) 转为小写
space(int_expr) 生成int_expr个空格 ......
sql权限:
创建User:
insert into mysql.user(Host,User,Password)
values("localhost","cordev",password("xasoftorg"));
insert into
mysql.user(Host,User,Password)
values("localhost","corhotfix",password("xasoftorg"));
insert into
mysq ......
在写sql语句时,一般都是一句解决,从来没想过说,把sql语句拆开来写。
例如下面这句: string readstring = "select * from 实例 where 实例ID='"+eid+"'";
然后执行 Myconnection();
DataSet ds = new DataSet();
OleD ......
2010-06-01 10:23
数据类型
描述
字节
推荐使用
SMALLINT
整数,从-32000到 +32000范围
2
存储相对比较小的整数。
比如: 年纪,数量
INT
整数,从-2000000000 到 +2000000000 范围
4
存储中等整数
例如: 距离
BIGINT
不能用SMALLINT 或 INT描述的超大整数。
8
存储超大的整数
例如: 科学/数学数据
FLOA ......