CentOS下配置MySQL的编码:
0.安装mysql:sudo yum install mysql mysql-server mysql-devel
1.启动服务: /etc/rc.d/init.d/mysqld start
2.修改root密码: mysqladmin -uroot password 'yourpassword'
3.修改启动文件: /etc/rc.d/init.d/mysqld :
CentOS 5 自带的 Mysql5.0.22里是此处,添加 --default-character-set=utf8 :
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --pid-file="$mypidfile" --log-error="$errlogfile" >/dev/null --default-character-set=utf8
2>&1 &
CentOS5.2里自带的Mysql5.0.45里是此处, 添加 --default-character-set=utf8 :
/usr/bin/mysqld_safe --datadir="$datadir" --socket="$socketfile" \
--log-error="$errlogfile" --pid-file="$mypidfile" \
>/dev/null --default-character-set=utf8
2>&1 &
OpenSuse11.3的Mysql-5.1.46-log SUSE MySQL RPM是在大约259行,添加default_character_set=utf8 :
pid_file=/var/run/mysql/mysqld.pid
socket=/var/run/mysql/mysql.sock
print_defaults=/usr/bin/my_print_defaults
log_error=/var/log/mysql/mysqld.log
default_character_set=utf8
mode=$1 # start or stop
log_base="`echo "$log_error" | sed 's|\.log$||'`"
CentOS 6.0 自带的MySQL 5.1.52,是在大约 第99行,添加 --character-set-server=utf8 :
$exec --datadir="$datadir" --socket="$socketfile" \
--pid-file="$mypidfile" \
--basedir=/usr --user=mysql >/dev/null --character-set-server=utf8
2>&1 &
注意这里用的是 --character-set-server=utf8
。
4.修改my.conf
[ mysqld]
max_allowed_packet = 2M
max_connections = 1000
default-character-set=utf8 (注意:在CentOS6里, 这里 应该是 character-set-server =utf8)
init_connect='SET NAMES utf8'
[client]
default-character-set=utf8
5.重启服务:/etc/init.d/mysqld restart
6.测试结果:
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
smysql> status;
--------------
mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0
Connection id: 2
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.0.45 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 15 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 6 Queries per second avg: 0.267
--------------
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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
7.以上在
OpenSuse11.3, Server version: 5.1.46-log SUSE MySQL RPM;
CentOS5.4, mysql 5.0.77;
CentOS5.2, mysql-5.0.45;
CentOS5.0, mysql-5.0.22;
CentOS4.6, mysql-5.0.27
CentOS 6.0, mysql-5.1.52 上均测试通过.
2 楼 shellfish 2012-08-27 10:11
1 楼 dxf1122 2012-08-11 13:20