mysql怎么插入汉字 mysql怎么输入中文( 二 )


需要注意的时,如果你打算把这条命令放在你的rc.local里面,必须确认在执行这条指令时MySQL服务器必须没有启动!检测修复所有数据库(表)
怎样往MYSQL输入汉字?有两种方法...你试一下...不行的话加我的QQ
76558882
1.
修改
mysql
安装目录下的
my.ini
修改
default-character-set=latin1
把latin1
改为
gb2312

gbk
注意:
修改两处
CLIENT
SECTION
#
----------------------------------------------------------------------
#
#
The
following
options
will
be
read
by
MySQL
client
applications.
#
Note
that
only
client
applications
shipped
by
MySQL
are
guaranteed
#
to
read
this
section.
If
you
want
your
own
MySQL
client
program
to
#
honor
these
values,
you
need
to
specify
it
as
an
option
during
the
#
MySQL
client
library
initialization.
#
[client]
port=3306
[mysql]
default-character-set=latin1
//把
latin1
改为
gb2312或
gbk
#
SERVER
SECTION
#
----------------------------------------------------------------------
#
#
The
following
options
will
be
read
by
the
MySQL
Server.
Make
sure
that
#
you
have
installed
the
server
correctly
(see
above)
so
it
reads
this
#
file.
#
[mysqld]
#
The
TCP/IP
Port
the
MySQL
Server
will
listen
on
port=3306
#Path
to
installation
directory.
All
paths
are
usually
resolved
relative
to
this.
basedir="C:/Program
Files/MySQL/MySQL
Server
5.0/"
#Path
to
the
database
root
datadir="C:/Program
Files/MySQL/MySQL
Server
5.0/Data/"
#
The
default
character
set
that
will
be
used
when
a
new
schema
or
table
is
#
created
and
no
character
set
is
defined
default-character-set=latin1
//将latin1
改为
gb2312

gbk
2.
进入在命令提示符下登录mysql
输入
charset
gb2312
你再尝试使用
insert
into
插入一条记看看...
怎样设置使mysql支持中文的插入?支持插入中文的前提是:你的数据库编码和mysql连接所使用的字符集要相同,即:你的数据库(comment)的字符集是GBK的,那么你在数据库连接(mysql_connect)时要加上一句mysql_query('set
names
gbk');
这样的话就不会出现中文插入时出现乱码现象 。UTF8字符集时与GBK同理 。
还有疑问?
mysql怎样在查出结果后的字段前后添加文字有两种方式进行字符添加:
第一种:在PHP中遍历数据mysql怎么插入汉字,然后对字段进行字符串操作从而达到目标
第二种:直接在SQL语句中使用函数对字段mysql怎么插入汉字的结果进行处理
例1- PHP遍历方式
//假设$rows是结果集foreach ($rows as $row) {$row['column'] = sprintf("前面%s后面", $row['column']); //方法1.1$row['column2'] = "前面{$row['column2]}后面"; //方法1.2}

推荐阅读