UTF-8(8位元,Universal Character Set/Unicode Transformation Format)是针对Unicode的一种可变长度字符编码。它可以用来表示Unicode标准中的任何字符,而且其编码中的第一个字节仍与ASCII相容,使得原来处理ASCII字符的软件无须或只进行少部分修改后,便可继续使用。因此,它逐渐成为电子邮件、网页及其他存储或传送文字的应用中,优先采用的编码。
对应用程序来说,强制将它们发起的数据库链接设置成UTF8编码有什么办法? 每个链接建立时先执行set names utf8; [mysqld] init-connect=‘set names utf8’ 语句set names UTF8是什么作用? 比如一个set names语句相当于执行了以下三行语句 SET character_set_client = charset_name SET character_set_results = charset_name SET character_set_connection = charset_name
[root@localhost ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c)2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| 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 inset(0.00 sec)
MariaDB [(none)]>exit;[root@localhost ~]# sed -i '/\[mysqld\]/a\character_set_server=utf8' /etc/my.cnf[root@localhost ~]# sed -i '/\[mysqld\]/a\init_connect="SET NAMES utf8"' /etc/my.cnf[root@localhost ~]# systemctl restart mariadb[root@localhost ~]# mysql -h localhost -P3306 -uroot -p'000000' -se "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/
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf##修改一下参数
ServerName localhost:8080
Listen 8080