首页 > 网络相关 > MySQL 24小时大作战
2012
09-23

MySQL 24小时大作战

环境1. IX webhosting  Linux OS

       2. Win7 OS / Xampp1.77

资料 数据库大小 16MB 其中某一表格有10MB

        某小朋友的一个基于DEDECMS 5.7.1的网站 自从6月分升级到 SP1后,网站后台某些操作出现严重权限问题,多次联系IX 客服修改权限勉强能执行某些操作,但过一段时间后又再次出现同样问题。于是一场伟大的网站搬家计划就激活了。

    由于CMS 后台数据备份功能被提示权限不足,于是通过phpmysql 直接下载数据,然后再上传,但受到网速及服务器数据库访问时限的制约,多次试验后,这个方法不怎么行。后来使用了SQLyog 终于可以下载数据了,而且比较完整。不过上传方面还是受到网速及数据库访问时限的制约,出现了严重的问题。数据是下载下来了,但不能上传!!!

  经本地测试,发现都不能上传 SQLyog 错误提示“Error Code: 2006-MySQL server has gone away” 网络搜索后,得到以下解决办法(对环境2 适用),在xampp1.77/bin/ 里面有一my.ini  把里面相关数值修改下,下面仅为参考(如整体复制,请务必注意修改红色部分的路径,需要与你软件所在地路径一样!!!),请根据实际情况修改,其中的wait-timeout,interactive-timeout ,max_allowed_packet 较为重要。

# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it’s important that the mysqld daemon
# doesn’t use much resources.
#
# You can copy this file to
# D:/xampp1.77/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is D:/xampp1.77/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the “–help” option.

# The following options will be passed to all MySQL clients
[client]
# password       = your_password
port            = 3306
socket          = “D:/xampp1.77/mysql/mysql.sock”

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port= 3306
socket = “D:/xampp1.77/mysql/mysql.sock”
basedir = “D:/xampp1.77/mysql
tmpdir = “D:/xampp1.77/tmp
datadir = “D:/xampp1.77/mysql/data”
pid_file = “mysql.pid”
skip-external-locking
key_buffer = 16M
max_allowed_packet = 100M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = “mysql_error.log”
 
#bind-address=”127.0.0.1″

# Where do all the plugins live
plugin_dir = “D:/xampp1.77/mysql/data/lib/plugin/”

# Don’t listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the “enable-named-pipe” option) will render mysqld useless!
#
# commented in by lampp security
#skip-networking
skip-federated

# Replication Master Server (default)
# binary logging is required for replication
# log-bin deactivated by default since XAMPP 1.4.11
#log-bin=mysql-bin

# required unique id between 1 and 2^32 – 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) –
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master’s port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST=’125.564.12.1′, MASTER_PORT=3306,
#    MASTER_USER=’joe’, MASTER_PASSWORD=’secret’;
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables’ values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 – 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave – required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master – required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master – required
#master-password =   <password>
#
# The port the master is listening on.
# optional – defaults to 3306
#master-port     =  <port>
#
# binary logging – not required for slaves, but recommended
#log-bin=mysql-bin
# Point the following paths to different dedicated disks
#tmpdir = “D:/xampp1.77/tmp”
#log-update = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000

# Comment the following if you are using InnoDB tables
#skip-innodb
innodb_data_home_dir = “D:/xampp1.77/mysql/data”
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = “D:/xampp1.77/mysql/data”
#innodb_log_arch_dir = “D:/xampp1.77/mysql/data”
## You can set .._buffer_pool_size up to 50 – 80 %
## of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 100M
## Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 502220

## UTF 8 Settings
#init-connect=’SET NAMES utf8′
#collation_server=utf8_unicode_ci
#character_set_server=utf8
#skip-character-set-client-handshake
#character_sets-dir=”D:/xampp1.77/mysql/share/charsets”

[mysqldump]
quick
max_allowed_packet = 160M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout = 502220

 修改完后可以上传了,但到最后还是失败,SQLyog 错误提示“Error Code: 1231 – Variable ‘sql_mode’ can’t be set to the value of ‘NULL’”网络搜索后得到以下解决方法,删除你使用SQL yog 下载的数据里面头尾有如此的一段注释,

 头部

/*!40101 SET SQL_MODE=”*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`此处为数据库名称 ` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `此处为数据库名称`;

 

尾部

 

/*!40101 SET SQL_MODE=@OLD_SQL_MODE”>SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS”>FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS”>UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES”>SQL_NOTES=@OLD_SQL_NOTES */;

 

这2部分是在使用SQLyog 下载的时候自动产生的,跟你下载的时候选择的选项有关,譬如我当时是这样选择的,结果下载的数据库就的头部/尾部就有了不同的注释了,目前测试中,无论你遇到那种情况,只要删除头尾2部分的注释,都可以重新上传

MySQL 24小时大作战 - HELLOCOOBY - 1

本地的问题基本上解决了,接下来需要做的是怎样把本地的数据库搬到网络服务器上,想起了一备份工具“EmpireBak”以前有使用过,感觉还可以。由于知道网络服务器数据库有写入时间及大小的限制,也就是每个表不能太大,如果超过了限制也是失败的。所以在使用EmpireBak的时候可以把每组备份大小 设定的值可以调在合适的范围。本地备份成功了。接下来在网站上安装EmpireBak回复在本地备份的数据库即可。

   登录网站后台查看,一切如旧。所有都不用重新设定。

注意事项

网站升级前最好做下功课,譬如数据备份,有关功能测试,随时准备另外一个可运行的网站或在另外一个空间进行升级测试。

上文有关软件如有需要可以自行下载。 

 

 

 

 

 

 

 

作者:Cooby
这个作者貌似有点懒,什么都没有留下。

MySQL 24小时大作战》有 1 条评论

  1. MR ACY 说:

    😳 不错,很有用

留下一个回复

你的email不会被公开。