linuxでデータベースmysql文字を変更してUTF 8に符号化
7450 ワード
mysql UTF8
Mysql , 。 mysql 。
1:
mysql> show variables like'character%';
+--------------------------+----------------------------+
|Variable_name |Value |
+--------------------------+----------------------------+
|character_set_client |latin1 |
| character_set_connection |latin1 |
| character_set_database |latin1 |
| character_set_filesystem |binary |
|character_set_results |latin1 |
|character_set_server |latin1 |
|character_set_system |utf8 |
|character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
latin1 , (char) , , mysql UTF8。 :
2: my.cnf , (<span style="color: rgb(51, 51, 51); font-family: ; line-height: 28px; text-indent: 28px;">/etc/my.cnf</span>):
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8 # UTF8
</pre><pre id="best-answer-content" class="reply-text mb10" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: Arial; zoom: 1; line-height: 22px; background-color: rgb(255, 252, 246);">===================================================================================================================
<dl class="box_t" style="border-width: 0px; padding: 15px 0px 0px; margin: 0px; list-style: none; float: left; width: 670px; height: 35px; text-align: center; font-size: 21px; font-weight: bold; font-family: ;"><dd style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;">Mysql </dd></dl><dl class="box_body" id="fontzoom" style="border-width: 0px; padding: 0px 20px 20px; margin: 0px; list-style: none; float: left; width: 630px; color: rgb(51, 51, 51); line-height: 28px; font-family: ;"><dd id="Article" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; float: left;"><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;">
MySQL :
1.server , latin1
2.table ( character collation)
3. ( <a target=_blank href="http://www.2cto.com/kf/web/php/" target="_blank" class="keylink" style="color: rgb(51, 51, 51); text-decoration: none;">php</a>)
utf8!!!!
utf8 !!!!
、
1、 :CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
2、 CREATE TABLE `database_user` (
`ID` varchar(40) NOT NULL default '',
`UserID` varchar(40) NOT NULL default '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;</p><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;"> 3 , , 。
。
1. :
mysql> show variables like "%char%";
+--------------------------+---------------+
| Variable_name | Value |
+--------------------------+---------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
+--------------------------+-------------+
: 2 , set names utf8,set names gbk ;</p><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;"> SET NAMES utf8 :
SET character_set_client='utf8';
SET character_set_connection='utf8';
SET character_set_results='utf8';</p><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;">2. test :
mysql> show create database test;
+------------+------------------------------------------------------------------------------------------------+
| Database | Create Database |
+------------+------------------------------------------------------------------------------------------------+
| test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET gbk */ |
+------------+------------------------------------------------------------------------------------------------+</p><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;">3. yjdb :
mysql> show create table yjdb;
| yjdb | CREATE TABLE `yjdb` (
`sn` int(5) NOT NULL AUTO_INCREMENT,
`type` varchar(10) NOT NULL,
`brc` varchar(6) NOT NULL,
`teller` int(6) NOT NULL,
`telname` varchar(10) NOT NULL,
`date` int(10) NOT NULL,
`count` int(6) NOT NULL,
`back` int(10) NOT NULL,
PRIMARY KEY (`sn`),
UNIQUE KEY `sn` (`sn`),
UNIQUE KEY `sn_2` (`sn`)
) ENGINE=MyISAM AUTO_INCREMENT=1826 DEFAULT CHARSET=gbk ROW_FORMAT=DYNAMIC |</p><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;"> 、
1: utf-8
utf8:
set names utf8;
db_name utf8:
ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
tb_name utf8:
ALTER TABLE `tb_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
:
LOAD DATA LOCAL INFILE 'C:\\utf8.txt' INTO TABLE yjdb;
2: ansi( GBK GB2312)
gbk:
set names gbk;
db_name gbk:
ALTER DATABASE `db_name` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
tb_name gbk:
ALTER TABLE `tb_name` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
:
LOAD DATA LOCAL INFILE 'C:\\gbk.txt' INTO TABLE yjdb;</p><p style="margin-top: 0px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; border-width: 0px; list-style: none; text-indent: 2em;"> :1.UTF8 gbk,gbk UTF8;
2.<a target=_blank href="http://www.2cto.com/os/dos/" target="_blank" class="keylink" style="color: rgb(51, 51, 51); text-decoration: none;">dos</a> UTF8 ;
、
utf-8, 。
, , , GBK, GBK GB2312 :GBK GB2312 , , GBK。
1. /etc/my.cnf , [<a target=_blank href="http://www.2cto.com/database/mysql/" target="_blank" class="keylink" style="color: rgb(51, 51, 51); text-decoration: none;">mysql</a>] default_character_set=utf8;
2. Connection URL , ?useUnicode=true&characterEncoding=utf-8 ;
3. "set names utf8" "set names gbk" , MySQL
utf8 gbk;</p></dd></dl>