Linux Study Notes & mdash; mysql modification code utf8 in ubuntu abstract: Using ap Linux study notes -- mysql modification code utf8 in ubuntu
Abstract: mysql installed using the apt-get command is not utf8 by default. here, record how to change the encoding to utf8.
I. View mysql version 1.1 mysql-V
Enter the above command on the terminal interface and display it as follows:
mysql Ver 14.14 Distrib 5.5.35, fordebian-linux-gnu (x86_64) using readline 6.2
1.2 status
A) log on to mysql
mysql –uroot –ppassword
B) enter the following command:
status
# The following figure shows: -------------- mysql Ver 14.14 Distrib5.5.35, for debian-linux-gnu (x86_64) using readline 6.2 Connection id: 45 Current database: Current user: root @ localhost SSL: not inuse Current pager: stdout Using outfile: ''Using delimiter:; Server version: 5.5.35-0ubuntu0. 12.04.2 (Ubuntu) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket:/var/run/mysqld. sock Uptime: 1 hour15 min 13 sec Threads: 1 Questions: 609 Slow queries: 0 Opens: 421 Flush tables: 1 Open tables: 41 Queries per second avg: 0.134 --------------
1.3 selectversion ();
A) log on to mysql
mysql –uroot –ppassword
B) enter the following command:
Select version (); # The following figure is displayed: + ----------------------- + | version () | + versions + | 5.5.35-0ubuntu0. 12.04.2 | + ----------------------- + 1 row in set (0.00 sec)
II. View mysql code 2.1 and log on to mysql
A) enter the following command:
mysql –uroot –p
B) enter the password:
password
2.2 View mysql encoding
Show variables like '% character %'; # The following is displayed: + bytes + | Variable_name | Value | + bytes + | character_set_client | utf8 | character_set_connection | utf8 | character_set_database | latin1 | bytes | binary | bytes | utf8 | | character_set_server | latin1 | character_set_system | utf8 | character_sets_dir |/usr/share/mysql/charsets/| + ---------------------- + rows + 8 rows in set (0.00 sec)
III. modify mysql encoding
The code of the red part -- latin1
3.1 modify the mysql configuration file --/etc/mysql/my. cnf:
A) open the mysql configuration file:
vim/etc/mysql/my.cnf
B) append an object under [client:
default-character-set=utf8
C) append an object under [mysqld:
character-set-server=utf8
D) append an object under [mysql:
default-character-set=utf8
E) save and exit
3.2 restart the mysql service
Either of the following two can be:
servicemysql restart /etc/init.d/mysqlrestart
3.3 check whether mysql encoding is modified successfully
A) log on to mysql
B) input:
Show variables like '% character %'; # The following is displayed: + bytes + | Variable_name | Value | + bytes + | character_set_client | utf8 | character_set_connection | utf8 | character_set_database | utf8 | bytes | binary | utf8 | | character_set_server | utf8 | character_set_system | utf8 | character_sets_dir |/usr/share/mysql/charsets/| + ---------------------- + bytes +
The modification is successful!