D:\mysql\mysql-5.1.40-win32\bin>mysqld --console
如果能看到
Version: '5.1.40-community-log' socket: '' port: 3306 MySQL Community Server
(GPL)
说明mysql服务启动成功。
连接mysql
同样在mysql的bin目录下执行命令:
D:\mysql\mysql-5.1.40-win32\bin>mysql -u root -p
Enter password: ************
登录成功后执行命令:
mysql> show variables like 'character%';
显示
mysql> show variables like 'character%';
+--------------------------+---------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\mysql\mysql-5.1.40-win32\share\charsets\ |
+--------------------------+---------------------------------------------+
8 rows in set (0.06 sec)
mysql字符集默认为Latin1,为了避免中文乱码,我们修改my.cnf配置文件即可。
找到[client] 添加:
default-character-set=utf8 //默认字符集为utf8
找到[mysqld] 添加:
//默认字符集为utf8
default-character-set=utf8
//设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行
init_connect='SET NAMES utf8'
重启mysql,再次查看
mysql> show variables like 'character%';
+--------------------------+---------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\mysql\mysql-5.1.40-win32\share\charsets\ |
+--------------------------+---------------------------------------------+
8 rows in set (0.00 sec)
ok,字符集成功修改。
分享到:
2009-12-08 08:08
浏览 1772
评论
1 楼
partoo
2010-02-25
辛苦了~