linux mysql乱码彻底解决

1、数据库目录,其所创建的数据库文件  :/var/lib/mysql/ 
2、配置文件 mysql.server命令和配置文件  :/usr/share/mysql 
3、相关命令:如mysql mysqladmin等:/usr/bin 

4、启动脚本:如mysql启动命令  /etc/rc.d/init.d/mysqld



mysql默认字符是latin1 ,修改成utf-8:

直接把下面这段拷贝到/etc/my.cnf中

#vi /etc/my.cnf

[client]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#default-character-set=utf8
character-set-server=utf8
init_connect='SET NAMES utf8'

[mysql]
no-auto-rehash
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


注意:在[mysqld]中:

character-set-server=utf8  (错误)

default-character-set=utf8  (正确)

否则会报:Starting MySQL...The server quit without updating PID file [失败]lib/mysql/localhost.localdomain.pid).异常


设置完毕,重新启动mysql:

#/etc/init.d/mysql  restart

[root@iZuf6bkbivtw79zmz2q0m9Z ~]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@iZuf6bkbivtw79zmz2q0m9Z ~]# 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.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| 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.00 sec)
解决完毕!!!!!

你可能感兴趣的:(服务器系列,-,Linux,Linux)