mysql支持中文的配置说明

修改/etc/mysql/my.cnf,增加下列几行

[mysqld]
character-set-server=utf8

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

登录mysql时出现如下错误:

mysql: Character set 'uft8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
mysql: Character set 'uft8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
ERROR 2019 (HY000): Can't initialize character set uft8 (path: /usr/share/mysql/charsets/)

查阅了很多资料都未能解决,问题恰恰出现在这里,后面指定的utf8改为大写。修改如下解决问题。

[mysqld]
character-set-server=UTF8

[client]
default-character-set=UTF8

[mysql]
default-character-set=UTF8

ubuntu安装mysql5.7

sudo apt-get install mysql-server
sudo apt-get install mysql-client

安全性的需要,不再提供root密码,需要自行设置。
执行以下命令,查找默认用户名和密码

sudo vim /etc/mysql/debian.cnf

用默认账号密码登陆后执行以下代码,修改root用户的密码,同时修改plugin模式

mysql> update mysql.user set authentication_string=password('您的密码'), plugin="mysql_native_password" where user='root' and Host = 'localhost';

接下来需要重启mysql服务。

sudo /etc/init.d/mysql restart