返回   CHF站长论坛 > 特色讨论区 > Joomla 讨论专区

Joomla 讨论专区 基于PHP开发的非常强大的开源CMS.。[官方]

双至强仅二千,企商在线,最早租用商 魔兽世界私服 魔兽世界私服 魔兽世界私服魔兽世界私服< 天龙八部私服 传奇世界私服 新开传奇私服
传奇私服 热血江湖私服 全球最新的创意科技产品 魔域私服 魔域私服 此文字广告位招租
发表新主题 回复
 
主题工具 主题评分 显示模式
旧 2007-01-25, 21:18   #1 (页面定位)
泪随风逝©
 
泪随风逝 的头像
 
注册日期: 2005-09-17
帖子: 2484
泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀
默认 joomla 数据库转换为UTF8编码的问题

joomla 在mysql5上默认安装后,即使mysql现在的编码是utf8了,joomla默认编码仍然是latin1,也就是在utf8的mysql5数据库里把所有内容存贮为latin1,对应的中文编码存贮方式就是gb2312。这样造成很多困扰,如phpmyadmin看到的joomla数据库内的中文为乱码等。

下面就以joomla 1.0.10为例,说明转换现有数据的过程。

1.用mysqldump导出要转换的数据.
mysqldump -u root -p --opt --default-character-set=latin1 --databases database > C:\joomla.sql

2.导出的joomla.sql文件用记事本查看,中文是乱码,用ultraedit看,可以看到中文,但如果直接用ultraedit转换为utf8的话,不管用mysql还是phpmyadmin导入时,都会报一些莫名奇妙的语法错误,如果直接用记事本转换同样不行.
最常用的转换方法应该时用iconv,*nix下都有,windows下可以用cygwin的iconv,网上一般说到mysql4.0转换到4.1或者 5.0时都用iconv (iconv -f gb2312 -t utf-8 joomla.sql > new.sql).但是这里我的数据库用iconv转换失败,只能转换前面一小部分.连iconv都不成功,看来导出的joomla.sql文件内部可能不是gb2312编码的了.

最后发现用notepad++打开导出的joomla.sql文件,然后把编码换成utf8,中文就显示正常了,这时候把文件保存到另一个文件joomla.new.sql .用记事本打开中文显示正常.
如果这时候直接用mysql -u root -p database < joomla.new.sql,不成功,提示第一行就错误,比较两个sql文件,只相差3字节,看来根本问题是按latin1导出的文件已经是utf8的了(奇怪的逻辑?mysql5本来就是用utf8来存储数据的),notepad++另存的文件只是在前面加了BOM的三个字节.其他内容没变!现在的问题是带BOM的mysql命令行导入失败,如果mysql命令行导入不带BOM的文件,效果跟原来一样,等于没导入.

3.用phpmyadmin导入
mysql命令行不能导入,看来只能用phpmyadmin了,打开phpmyadmin里的相应数据库,从notepad++内拷贝正常的sql语句,执行...居然也报语法错误?
最后再用记事本打开joomla.new.sql,再ctrl+A,拷贝到phpmyadmin执行,这次行了!!!
是在想不明白用notepad++和记事本拷贝有什么区别?
但就是只能这样才能通过,很奇怪的过程.所以记下来,如果别人碰到类似问题,看了以上的文字希望可以节省点时间.

4.再把joomla/includes/database.php内102行的那条语句前的"//"去掉,让joomla的数据库连接的编码直接用utf8,打开网站就正常了.

如果是新安装joomla的话
1.首先修改installation/sql/sql_simplified_chinese/joomla.sql内每个表的定义后面的分号前都加上一条DEFAULT CHARACTER SET utf8.

2.七百多行的表core_acl_aro的定义里把两个240换成160 (utf8每个字符占三个字节,而mysql默认的索引最长1000个字节,240*2*3>1000所以改为小于1000,运行一个月好像没什么影响).

3.把joomla/includes/database.php内102行的那条语句前的"//"去掉.

4.在phpmyadmin内把mysql的连接校对设置为utf8-unicode-ci,在mysql内新建一个数据库,默认的连接校对如上.

5.安装新joomla.
泪随风逝 当前离线   回复时引用此帖
旧 2007-01-26, 09:13   #2 (页面定位)
toll
 
toll 的头像
 
注册日期: 2005-09-06
住址: 江苏.盐城
帖子: 304
toll 正向着好的方向发展toll 正向着好的方向发展toll 正向着好的方向发展
默认

建议安装mysql之后,修改默认的编码格式

以下是我的mysql5.X的配置文件

引用:
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file".
#
# To run run the server from the command line, execute this in a
# command line shell, e.g.
# mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# To install the server as a Windows service manually, execute this in a
# command line shell, e.g.
# mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
#
# 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=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="D:/MySQL/MySQL Server 5.0/"

#Path to the database root
datadir="D:/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=gbk

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=100

# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=0

# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_cache=256

# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=9M


# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before. This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=8

#*** MyISAM Specific options

# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_max_extra_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=18M

# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=11M

# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K

# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K


#*** INNODB Specific options ***


# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb

# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=2M

# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1

# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=1M

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=18M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=10M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8
toll 当前离线   回复时引用此帖
旧 2007-01-26, 09:50   #3 (页面定位)
泪随风逝©
 
泪随风逝 的头像
 
注册日期: 2005-09-17
帖子: 2484
泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀泪随风逝 星途闪耀
默认

国内很多人用的都是虚拟主机,可能没有这个权限修改mysql的默认编码
泪随风逝 当前离线   回复时引用此帖
回复

书签

标签

主题工具
显示模式 对此主题评分
对此主题评分:



所有时间均为北京时间。现在的时间是 12:24