http://hi.baidu.com/hexiong/blog/item/e860e5dd9b0d3ae376c6381a.html (hexiong@baidu or iihero@CSDN) 偶尔碰到有人问使用mysql命令行,老让人输入--default-character-set=gbk之类无聊的选项,让人烦。让人多输入了几个字符,确实有点不对劲。 加上有时
http://hi.baidu.com/hexiong/blog/item/e860e5dd9b0d3ae376c6381a.html
(hexiong@baidu or iihero@CSDN)
偶尔碰到有人问使用mysql命令行,老让人输入--default-character-set=gbk之类无聊的选项,让人烦。让人多输入了几个字符,确实有点不对劲。
加上有时候自己有时候DIY,很少在windows上使用安装的版本,总是解压缩,然后放一个my.ini到解压缩目录下边的某一个特殊的位置。这样,mysql命令行,缺省情况下,反而load不到这个配置文件了。
关于my.ini文件的加载顺序,详见:http://hi.baidu.com/hexiong/blog/item/313534a8b7e0dcbdcb130cc5.html
以windows为例,它会这样加载:
C:/WINDOWS/my.cnf C:/WINDOWS/my.ini C:/my.cnf C:/my.ini
至于$installdir/my.ini,嘿, 不是安装版,这个变量估计是读不到了。
上述四个文件,只要前面的某一个文件加载成功,就不再加载后边指定的配置文件了。
所以,要想使mysql命令行直接使用gbk字符集,有下述方法:
1. 命令行:
mysql -u test -p --default-character-set=gbk
2. 命令行:
mysql --defaults-file=
注意 --defaults-file永远要放到第一个参数的位置
3. 直接制作一个客户端版本的my.ini,如:
#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions
[client]
port = 3306
default_character_set=gbk
把它存到c:/my.ini
这里需要说明的是:
如果你定制的mysql中my.ini文件本来就在上边4个路径里头,直接修改里边[client]下的default_character_set值为gbk好可。否则就可以生成一个专为client使用的my.ini
方法3虽然方便,但因为是全局配置文件,所以有时候不免会相互影响,尤其是一台机器有多个mysql。
这个时候,可以使用命令行:
d:/>mysql -u test -p --default-character-set=latin1
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 10 to server version: 5.0.9-beta-nt
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> show variables like 'char%';
+--------------------------+-------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | gbk |
| character_set_results | latin1 |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | d:/mysql-5.0.9-beta-win32/share/charsets/ |
+--------------------------+-------------------------------------------+
7 rows in set (0.00 sec)
--default-character-set=latin1会覆盖全局文件my.ini中[client]的字符集选项值。
当然,如果我们仔细查看源代码,还会发现$INSTALLDIR指的就是环境变量:MYSQL_HOME,呵呵。
如果你指定了MYSQL_HOME,在找不到前边4个文件的时候,它会去查找$MYSQL_HOME/my.cnf或my.ini
相关源码如下:
static const char **init_default_directories(MEM_ROOT *alloc)
{
const char **dirs;
char *env;
int errors= 0;
dirs= (const char **)alloc_root(alloc, DEFAULT_DIRS_SIZE * sizeof(char *));
if (dirs == NULL)
return NULL;
bzero((char *) dirs, DEFAULT_DIRS_SIZE * sizeof(char *));
#ifdef __WIN__
{
char fname_buffer[FN_REFLEN];
if (my_get_system_windows_directory(fname_buffer, sizeof(fname_buffer)))
errors += add_directory(alloc, fname_buffer, dirs);
if (GetWindowsDirectory(fname_buffer, sizeof(fname_buffer)))
errors += add_directory(alloc, fname_buffer, dirs);
errors += add_directory(alloc, "C:/", dirs);
if (my_get_module_parent(fname_buffer, sizeof(fname_buffer)) != NULL)
errors += add_directory(alloc, fname_buffer, dirs);
}
#elif defined(__NETWARE__)
errors += add_directory(alloc, "sys:/etc/", dirs);
#else
errors += add_directory(alloc, "/etc/", dirs);
errors += add_directory(alloc, "/etc/mysql/", dirs);
#if defined(DEFAULT_SYSCONFDIR)
if (DEFAULT_SYSCONFDIR != "")
errors += add_directory(alloc, DEFAULT_SYSCONFDIR, dirs);
#endif /* DEFAULT_SYSCONFDIR */
#endif
if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV))))
errors += add_directory(alloc, env, dirs);
/* Placeholder for --defaults-extra-file=*/
errors += add_directory(alloc, "", dirs);
#if !defined(__WIN__) && !defined(__NETWARE__)
errors += add_directory(alloc, "~/", dirs);
#endif
return (errors > 0 ? NULL : dirs);
}
就分析这么多了。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

在mysql中,可利用“ALTER TABLE 表名 DROP INDEX unique key名”语句来删除unique key;ALTER TABLE语句用于对数据进行添加、删除或修改操作,DROP INDEX语句用于表示删除约束操作。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools