我的mysql数据库版本5.1.38-rc。sphinx-0.9.9最新稳定版。linux版本centos 5.4
安装:(utf8)
#先解压缩
tar zxvf mysql-5.1.38.tar.gz
tar zxvf sphinx-0.9.9.tar.gz
先将/soft/sphinx-0.9.9/mysqlse下的文件复制至/soft/mysql-5.1.38/storage/sphinx
cd sphinx-0.9.9/
cp -rf sphinx-0.9.9/mysqlse mysql-5.1.38/storage/sphinx
查看目录下是否有指定的文件。
然后先编译安装mysql:
cd mysql-5.1.38/
./configure --with-plugins=sphinx --prefix=/usr/local/mysql/ --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-readline --with-big-tables
--with-plugins=sphinx 一定要加入这条参数。意思是让他支持我们的sphinx数据扩展,与mysql-5.1.38/storage/sphinx 下的目录名字保持一致。
又出错error: No curses/termcap library found错误。
yum install libncurses5-dev
安装这个先,继续:
再出现个错误:error: unknown plugin: sphinx
执行
sh BUILD/autorun.sh
继续出错:BUILD/autorun.sh: line 23: aclocal: command not found
需要安装automake,yum install automake,yum install libtool继续执行:
无错了。
在mysql安装目录check下sphinx插件
./configure -h | grep sphinx
Plugin Name: sphin
然后再 重新编译configure:
./configure --with-plugins=sphinx --prefix=/usr/local/mysql/
--with-charset=utf8 --with-extra-charsets=complex
--enable-thread-safe-client --enable-assembler --with-readline
--with-big-tables --with-embedded-server --enable-local-infile
编译提示:Thank you for choosing MySQL!
看来是ok了,make && make install
增加mysql用户并添加进组。
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cd ../
创建MySQL数据库存放目录
mkdir -p /storage/mysql/3306/da
chown -R mysql:mysql /storage/mysql/
以mysql用户帐号的身份建立数据表:
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/storage/mysql/3306/da
创建my.cnf配置文件:(如果以前使用的是innodb数据扩展)注意的是将原来的innodb配置数据参数删除或注释)
vi /storage/mysql/3306/my.cnf
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="(\u:www.yzz.com:)[\d]> "
no-auto-rehash
[mysqld]
default-character-set = utf8
user = mysql
pid-file = /storage/mysql/3306/mysql.pid
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /storage/mysql/3306/da
open_files_limit = 10240
back_log = 600
max_connections = 3000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_b?r_size = 2M
join_b?r_size = 2M
thread_cache_size = 300
thread_concurrency = 8
qry_cache_size = 32M
qry_cache_limit = 2M
qry_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_qry_time = 1
log_long_format
log-bin = /storage/mysql/3306/binlog
log = /storage/mysql/3306/da
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_b?r_size = 256M
read_b?r_size = 1M
read_rnd_b?r_size = 16M
bulk_insert_b?r_size = 64M
myisam_sort_b?r_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1
#innodb_additional_mem_pool_size = 16M
#innodb_b?r_pool_size = 2048M
#innodb_da
#innodb_file_io_threads = 4
#innodb_thread_concurrency = 8
#innodb_flush_log_at_trx_commit = 2
#innodb_log_b?r_size = 16M
#innodb_log_file_size = 128M
#innodb_log_files_in_group = 3
#innodb_max_dirty_pages_pct = 90
#innodb_lock_wait_timeout = 120
#innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 32M
创建管理MySQL数据库的shell脚本:
vi /storage/mysql/3306/mysql
#!/bin/sh
mysql_port=3306
mysql_username="admin"
mysql_password="12345678"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe
--defaults-file=/storage/mysql/${mysql_port}/my.cnf 2>&1 >
/dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /storage/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
fi
赋予shell脚本可执行权限:
chmod +x /storage/mysql/3306/mysql
把mysql服务加入启动项:
cp -rf /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
启动MySQL:
/storage/mysql/3306/mysql start
/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sock #套接子文件
输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
运行show engines;,看是不是有一个叫sphinx的engine,有的话就表示sphinxSE(mysql的sphinx引擎)安装正常了.(看support的sphinx是否yes。代表正常)
接下来安装sphinx:
cd /soft/sphinx-0.9.9,运行
ldconfig /usr/local/mysql/lib/mysql
ldconfig /usr/local/mysql/incl?/mysql
./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql
make && make install
安装完成后
将sphinx.conf.dist拷贝/usr/local/sphinx/etc/sphinx.conf
cp -rf sphinx.conf.dist /usr/local/sphinx/etc/sphinx.conf
sphinx.conf配置代码:注意# 源 src1是utf8编码,test1为src1索引。src2是gbk编码,test2为src2索引。
##### 源 ###########
source src1
{
type = mysql
sql_host = localhost
sql_user = admin
sql_pass = 12345678
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_sock = /tmp/mysql.sock
sql_qry_pre = SET NAMES UTF8
sql_qry_pre = SET SESSION qry_cache_type=OFF
sql_qry_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents
sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
#sql_qry_range = SELECT MIN(id),MAX(id) FROM documents
#sql_range_step = 1000
#sql_qry = SELECT * FROM documents WHERE id>=$start AND id<=$send
#####以下是用来过滤或条件查询的属性############
sql_attr_uint = group_id
sql_attr_timestamp = date_added
sql_ranged_throttle = 1000
sql_qry_info = SELECT * FROM documents WHERE id=$id
}
### 索引 ###
index test1
{
####声明索引源
source = src1
path = /usr/local/sphinx/var/da
docinfo = extern
mlock = 0
morphology = none
#### 索引的词最小长度
min_word_len = 1
charset_type = utf-8
html_strip = 0
##### 字符表,注意:如使用这种方式,则sphinx会对中文进行单字切分,
##### 即进行字索引,若要使用中文分词,必须使用其他分词插件如 coreseek,sfc
charset_table = U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z,\
A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6,\
U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101,\
U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109,\
U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F,\
U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, \
U+0116->U+0117,U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D,\
U+011D,U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, \
U+0134->U+0135,U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, \
U+013C,U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, \
U+0143->U+0144,U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, \
U+014B,U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, \
U+0152->U+0153,U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159,\
U+0159,U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, \
U+0160->U+0161,U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, \
U+0167,U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, \
U+016E->U+016F,U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175,\
U+0175,U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, \
U+017B->U+017C,U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, \
U+0430..U+044F,U+05D0..U+05EA, U+0531..U+0556->U+0561..U+0586, U+0561..U+0587, \
U+0621..U+063A, U+01B9,U+01BF, U+0640..U+064A, U+0660..U+0669, U+066E, U+066F, \
U+0671..U+06D3, U+06F0..U+06FF,U+0904..U+0939, U+0958..U+095F, U+0960..U+0963, \
U+0966..U+096F, U+097B..U+097F,U+0985..U+09B9, U+09CE, U+09DC..U+09E3, U+09E6..U+09EF, \
U+0A05..U+0A39, U+0A59..U+0A5E,U+0A66..U+0A6F, U+0A85..U+0AB9, U+0AE0..U+0AE3, \
U+0AE6..U+0AEF, U+0B05..U+0B39,U+0B5C..U+0B61, U+0B66..U+0B6F, U+0B71, U+0B85..U+0BB9, \
U+0BE6..U+0BF2, U+0C05..U+0C39,U+0C66..U+0C6F, U+0C85..U+0CB9, U+0CDE..U+0CE3, \
U+0CE6..U+0CEF, U+0D05..U+0D39, U+0D60,U+0D61, U+0D66..U+0D6F, U+0D85..U+0DC6, \
U+1900..U+1938, U+1946..U+194F, U+A800..U+A805,U+A807..U+A822, U+0386->U+03B1, \
U+03AC->U+03B1, U+0388->U+03B5, U+03AD->U+03B5,U+0389->U+03B7, U+03AE->U+03B7, \
U+038A->U+03B9, U+0390->U+03B9, U+03AA->U+03B9,U+03AF->U+03B9, U+03CA->U+03B9, \
U+038C->U+03BF, U+03CC->U+03BF, U+038E->U+03C5,U+03AB->U+03C5, U+03B0->U+03C5, \
U+03CB->U+03C5, U+03CD->U+03C5, U+038F->U+03C9,U+03CE->U+03C9, U+03C2->U+03C3, \
U+0391..U+03A1->U+03B1..U+03C1,U+03A3..U+03A9->U+03C3..U+03C9, U+03B1..U+03C1, \
U+03C3..U+03C9, U+0E01..U+0E2E,U+0E30..U+0E3A, U+0E40..U+0E45, U+0E47, U+0E50..U+0E59, \
U+A000..U+A48F, U+4E00..U+9FBF,U+3400..U+4DBF, U+20000..U+2A6DF, U+F900..U+FAFF, \
U+2F800..U+2FA1F, U+2E80..U+2EFF,U+2F00..U+2FDF, U+3100..U+312F, U+31A0..U+31BF, \
U+3040..U+309F, U+30A0..U+30FF,U+31F0..U+31FF, U+AC00..U+D7AF, U+1100..U+11FF, \
U+3130..U+318F, U+A000..U+A48F,U+A490..U+A4CF
min_prefix_len = 0
min_infix_len = 1
ngram_len = 1
}
source src2
{
type = mysql
sql_host = localhost
sql_user = admin
sql_pass = 12345678
sql_db = gbk
sql_port = 3306 # optional, default is 3306
sql_sock = /tmp/mysql.sock
sql_qry_pre = SET NAMES gbk
sql_qry_pre = SET character_set_client=gbk
sql_qry_pre = SET character_set_connection=gbk
sql_qry_pre = SET character_set_results=utf8
sql_qry_pre = SET SESSION qry_cache_type=OFF
sql_qry_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents
sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
#sql_qry_range = SELECT MIN(id),MAX(id) FROM documents
#sql_range_step = 1000
#sql_qry = SELECT * FROM documents WHERE id>=$start AND id<=$send
#####以下是用来过滤或条件查询的属性############
sql_attr_uint = group_id
sql_attr_timestamp = date_added
sql_ranged_throttle = 1000
sql_qry_info = SELECT * FROM documents WHERE id=$id
}
### 索引 ###
index test2
{
####声明索引源
source = src2
path = /usr/local/sphinx/var/da
docinfo = extern
mlock = 0
morphology = none
#### 索引的词最小长度
min_word_len = 1
charset_type = utf-8
html_strip = 0
##### 字符表,注意:如使用这种方式,则sphinx会对中文进行单字切分,
##### 即进行字索引,若要使用中文分词,必须使用其他分词插件如 coreseek,sfc
charset_table = U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z,\
A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6,\
U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101,\
U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109,\
U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F,\
U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, \
U+0116->U+0117,U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D,\
U+011D,U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, \
U+0134->U+0135,U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, \
U+013C,U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, \
U+0143->U+0144,U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, \
U+014B,U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, \
U+0152->U+0153,U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159,\
U+0159,U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, \
U+0160->U+0161,U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, \
U+0167,U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, \
U+016E->U+016F,U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175,\
U+0175,U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, \
U+017B->U+017C,U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, \
U+0430..U+044F,U+05D0..U+05EA, U+0531..U+0556->U+0561..U+0586, U+0561..U+0587, \
U+0621..U+063A, U+01B9,U+01BF, U+0640..U+064A, U+0660..U+0669, U+066E, U+066F, \
U+0671..U+06D3, U+06F0..U+06FF,U+0904..U+0939, U+0958..U+095F, U+0960..U+0963, \
U+0966..U+096F, U+097B..U+097F,U+0985..U+09B9, U+09CE, U+09DC..U+09E3, U+09E6..U+09EF, \
U+0A05..U+0A39, U+0A59..U+0A5E,U+0A66..U+0A6F, U+0A85..U+0AB9, U+0AE0..U+0AE3, \
U+0AE6..U+0AEF, U+0B05..U+0B39,U+0B5C..U+0B61, U+0B66..U+0B6F, U+0B71, U+0B85..U+0BB9, \
U+0BE6..U+0BF2, U+0C05..U+0C39,U+0C66..U+0C6F, U+0C85..U+0CB9, U+0CDE..U+0CE3, \
U+0CE6..U+0CEF, U+0D05..U+0D39, U+0D60,U+0D61, U+0D66..U+0D6F, U+0D85..U+0DC6, \
U+1900..U+1938, U+1946..U+194F, U+A800..U+A805,U+A807..U+A822, U+0386->U+03B1, \
U+03AC->U+03B1, U+0388->U+03B5, U+03AD->U+03B5,U+0389->U+03B7, U+03AE->U+03B7, \
U+038A->U+03B9, U+0390->U+03B9, U+03AA->U+03B9,U+03AF->U+03B9, U+03CA->U+03B9, \
U+038C->U+03BF, U+03CC->U+03BF, U+038E->U+03C5,U+03AB->U+03C5, U+03B0->U+03C5, \
U+03CB->U+03C5, U+03CD->U+03C5, U+038F->U+03C9,U+03CE->U+03C9, U+03C2->U+03C3, \
U+0391..U+03A1->U+03B1..U+03C1,U+03A3..U+03A9->U+03C3..U+03C9, U+03B1..U+03C1, \
U+03C3..U+03C9, U+0E01..U+0E2E,U+0E30..U+0E3A, U+0E40..U+0E45, U+0E47, U+0E50..U+0E59, \
U+A000..U+A48F, U+4E00..U+9FBF,U+3400..U+4DBF, U+20000..U+2A6DF, U+F900..U+FAFF, \
U+2F800..U+2FA1F, U+2E80..U+2EFF,U+2F00..U+2FDF, U+3100..U+312F, U+31A0..U+31BF, \
U+3040..U+309F, U+30A0..U+30FF,U+31F0..U+31FF, U+AC00..U+D7AF, U+1100..U+11FF, \
U+3130..U+318F, U+A000..U+A48F,U+A490..U+A4CF
min_prefix_len = 0
min_infix_len = 1
ngram_len = 1
}
# inherited source example
#
# all the parameters are copied from the parent source,
# and may then be overridden in this source definition
#source src1throttled : src1
#{
#sql_ranged_throttle = 100
#sql_qry_pre = SET NAMES UTF8
#sql_qry_pre = SET SESSION qry_cache_type=OFF
#sql_qry_pre =
#sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents \
#WHERE id>( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
#}
# inherited source example
#
# all the parameters are copied from the parent source,
# and may then be overridden in this source definition
#source src2throttled : src2
#{
#sql_ranged_throttle = 100
#sql_qry_pre = SET NAMES gbk
#sql_qry_pre = SET SESSION qry_cache_type=OFF
#sql_qry_pre =
#sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents \
#WHERE id>( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
#}
#index test1stemmed : test1
#{
#source = src1throttled
#path = /usr/local/sphinx/var/da
#morphology = none
#}
#index test2stemmed : test2
#{
#source = src2throttled
#path = /usr/local/sphinx/var/da
#morphology = none
#}
######### 索引器配置 #####
indexer
{
#内存限制
mem_limit = 32M
}
############ sphinx 服务进程 ########
searchd
{
port = 3312 #指定端口为3312.如果不加port参数。sphinx0.9.9版本默认为9312
log = /usr/local/sphinx/var/log/searchd.log
qry_log = /usr/local/sphinx/var/log/qry.log
read_timeout = 5
client_timeout = 300
max_children = 30
pid_file = /usr/local/sphinx/var/log/searchd.pid
max_matches = 1000
### 是否支持无缝切换,做增量索引时通常需要
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_vals = 4096
}
加载索引
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all #all代表test1.test2.
注: 先要给libmysqlclient.so.16 建立软链接
ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
再通过
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf 开启索引监听
为了下面测试方便,我们先将sphinx.conf自带的example.sql脚本倒入的mysql中
/usr/local/mysql/bin/mysql < /usr/local/sphinx/etc/example.sql //建立了一个test库,并建立了documents测试表和数据
/usr/local/mysql/bin/mysql < /usr/local/sphinx/etc/gbk.sql
测试:CLI上测试 命令端测试。
在上一步中,我们建立了索引,现在我们对刚建立的索引进行测试。测试有两种方式:CLI端和API调用
在CLI端上命令测试是使用sphinx自带的搜索命令:search
###### 在表索引上检索 “发生” 或者别的关键词
[root@localhost sphinx]# /usr/local/sphinx/bin/search -c /usr/local/sphinx/etc/sphinx.conf 发生
gbk编码
只需要修改my.cnf配置文件。
[client]
default-character-set = gbk
[mysqld]
default-character-set = gbk
修改完后,重启mysql服务就行了。
进入mysql指令查看mysql服务器编码与查询输出编码:
/usr/local/mysql/bin/mysql -uroot -p
mysql> SHOW VARIABLES LIKE 'character_set_%';
character_set_client =utf8 #客户端编码
character_set_connection=utf8 #客户端与服务器连接时的编码
character_set_database=gbk #数据库编码
character_set_results=utf8 #select 查询后将gbk转换成utf8