阿里云服务器安装后-安装配置MYSQL

01/12/2016

1.更新缓存,安装MYSQL服务

tianyangtax@iZ25tc8mln7Z:~$ sudo apt-get update
tianyangtax@iZ25tc8mln7Z:~$ sudo apt-get upgrade
tianyangtax@iZ25tc8mln7Z:~$ sudo apt-get install mysql-server

2.MYSQL默认字符编码为 latin1

tianyangtax@iZ25tc8mln7Z:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

Copyright (c) 2000, 2015, 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 "%char%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> quit
Bye

3.编辑配置文件 /etc/mysql/my.cnf

tianyangtax@iZ25tc8mln7Z:~$ sudo vim /etc/mysql/my.cnf
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /etc/mysql/my.cnf
...
[mysqld]
...
#
# * UTF-8 Settings
#
character-set-server    = utf8
collation-server        = utf8_general_ci
skip-character-set-client-handshake
...

4.重启MYSQL服务

tianyangtax@iZ25tc8mln7Z:~$ sudo service mysql restart
mysql stop/waiting
mysql start/running, process 8649

5.编码成功变更为UTF8

tianyangtax@iZ25tc8mln7Z:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

Copyright (c) 2000, 2015, 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 "%char%";
+--------------------------+----------------------------+
| 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)

mysql> quit
Bye