在CentOS上把MySQL从5.5升级到5.6

在CentOS上把MySQL从5.5升级到5.6

摘要:本文记录了在CentOS 6.3上,把MySQL从5.5.28升级到5.6.19的过程。

1. 概述

在我做的一个项目中,最近我对生产服务器上的一系列系统软件进行了升级,包括Git、Nginx、MySQL和PHP。这篇文章讲的是升级MySQL的过程,其他软件的升级,可见下面列出的文章。

在我加入这个项目之前,服务器上的MySQL已经安装设置好了,我只是正常使用而已。现在过去1年了,应该适当升级服务器上的软件了。升级这种事情是应当经常做的,倒不是为了追最新版本,而是当正式版本发放出来的时候,应该及时更新, 以便获得最新的更正、补丁,避免服务器上的漏洞,减少安全隐患。

升级是在今年6月11-12日进行的,到今天才有空做个记录,便于日后参考。

动手之前,查找了很多资料,因为MySQL要比之前升级的Git和Nginx要复杂多了。我在参考资料中列出了我所能找到作为依据的文档,可供参考。

2. 计划

我们使用的服务器是阿里云的,服务器的操作系统是CentOS 6.3。登录管理界面,发现共有两块物理硬盘,一块系统盘,一块数据盘,而我们只使用了系统盘,数据盘一直空着没用。所以,计划就变成:

  1. 加载数据硬盘
  2. 升级MySQL的同时,迁移MySQL数据到数据硬盘上。

3. 加载数据硬盘

下面的操作需要以超级管理员root的身份登录服务器进行操作。

3.1 查看硬盘

首先,查看硬盘使用情况:

# fdisk -l

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2550    20480000   83  Linux
/dev/xvda2            2550        2611      490496   82  Linux swap / Solaris

Disk /dev/xvdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             20G  9.4G   11G  48% /
tmpfs                 498M     0  498M   0% /dev/shm

可以看到,逻辑盘/dev/xvda1是位于根目录(/),/dev/xvda2是系统缓存(swap)。第二块物理硬盘/dev/xvdb的大小是21.5 GB,没有加载和使用,我们可以把它加载,并把MySQL的数据迁移到第二块物理硬盘上,把对系统盘和数据库的硬盘访问分流,希望这样一定程度上可以提高访问MySQL数据库的性能。

3.2 格式化数据硬盘

格式化第二块物理硬盘:

# mke2fs -j /dev/xvdb
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

格式化顺利完成。

3.3 加载数据硬盘

下面,加载第二块物理硬盘为/data目录:

# mount /dev/xvdb /data

这个命令没有反馈,当时我有点儿吃惊和失落。因为这许多命令我也都是第一次从网上查到,第一次使用,对于它们的输出和结果,都有一种第一次坐过山车般的期待、兴奋、好奇和不确定,每一次的输出对于我都是新的,你不知道翻过面前这个坡之后会出现什么!

再用下面的命令查看新的逻辑盘:

# df -kh
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             20G  9.3G   11G  48% /
tmpfs                 498M     0  498M   0% /dev/shm
/dev/xvdb              20G  173M   19G   1% /data

可以看到/dev/xvdb是第二块物理硬盘!激动,成功了!

用下面的命令查看加载(mount)的类型:

# mount
/dev/xvda1 on / type xfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/xvdb on /data type ext3 (rw)

到这里,第二块物理硬盘加载成功,下面该yum出场了。

4. 升级MySQL的计划

不好意思,yum同学,编剧说你还要等下一幕。

升级MySQL时,又做了两个计划:

  • 当然,首先要备份所有的数据库数据
  • 计划A: 使用参考资料[6]的方法,添加安装库,用yum update升级
  • 计划B: 用yum卸载MySQL 5.5,再安装MySQL 5.6

5. 计划A: yum update

下面大部分命令都需要在超级管理员root的权限下运行。

5.1 备份所有的数据库

用mysqldump来备份所有的数据库数据:

# mysqldump -u <db管理员用户名> -p --all-databases > 2014-06-12_all-db.sql

会提示输入密码,然后2014-06-11_all-db.sql就是备份数据,如果不想放在当前目录下,可以在上面的命令行上指定路径。

当然,也建议你单独备份每个用户数据库:

# mysqldump -u <db管理员用户名> -p mydb > 2014-06-12_mydb.sql

妥善保存这些非常重要的数据库备份文件。

5.2 查看MySQL的版本

用下面的命令查看MySQL的版本:

# mysql --version
mysql  Version 14.14 Distrib 5.5.28, for Linux (x86_64) using reeadline 5.1

可见,当前的MySQL的版本是5.5.28。

5.3 添加MySQL的yum安装库

这是参照参考资料[7]来做的,后来发现[6]的方法更好:

# wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
# yum list | grep mysql

这样很多更新的MySQL安装包就都有了。

如有必要,运行下面的命令确保yum安装库是最新的:

# yum update mysql-community-release

5.4 用yum查看MySQL安装相关信息

用下面的命令查看安装了什么:

# yum list installed | grep ^mysql
mysql-community-release.noarch

其中,^mysql是指以mysql开头的安装包。

用下面的命令查看安装了的和可用的安装包:

# yum info mysql-server
Installed Packages
Name        : MySQL-Server
Arch        : x86_64
Version     : 5.5.28
Release     : 1.linux2.6
Repo        : installed
Available Packages
Name        : mysql-server
Arch        : x86_64
Version     : 5.1.73
Release     : 3.el6_5
Repo        : updates

这里不知道为啥可用的安装包没有显示MySQL 5.6的。

检查可用的安装包:

# yum check-update mysql-server
Obsoleting Packages
mysql-community-client.x86_64      5.6.19-2.el6           mysql56-community
    MySQL-client.x86_64            5.5.28-1.linux2.6      installed
mysql-community-devel.x86_64       5.6.19-2.el6           mysql56-community
    MySQL-devel.x86_64             5.5.28-1.linux2.6      installed
mysql-community-server.x86_64      5.6.19-2.el6           mysql56-community
    MySQL-server.x86_64            5.5.28-1.linux2.6      installed

可见,MySQL 5.6的安装包都算community版本了。

5.5 升级MySQL及其组件

运行下面的命令:

# yum update mysql-server
Dependencies Resolved

================================================================================
 Package                   Arch      Version         Repository            Size
================================================================================
Installing:
 mysql-community-client    x86_64    5.6.19-2.el6    mysql56-community     18 M
     replacing  MySQL-client.x86_64 5.5.28-1.linux2.6
 mysql-community-server    x86_64    5.6.19-2.el6    mysql56-community     52 M
     replacing  MySQL-server.x86_64 5.5.28-1.linux2.6
Installing for dependencies:
 mysql-community-common    x86_64    5.6.19-2.el6    mysql56-community    298 k
 mysql-community-libs      x86_64    5.6.19-2.el6    mysql56-community    1.9 M

Transaction Summary
================================================================================
Install       4 Package(s)

后面的输出省略了。可见有4个安装包(共70多MB)要下载、安装。结果,下载用了80分钟。

但安装遇到问题了:

Running rpm_check_debug
Running Transaction Test


Transaction Check Error:
  file /usr/bin/mysql_config from install of mysql-community-client-5.6.19-2.el6
.x86_64 conflicts with file from package MySQL-devel-5.5.28-1.linux2.6.x86)64

Error Summary
-------------

可以看到出错了,搜索了一阵儿,也没搞明白。随即停止A计划(和成龙的电影没关系),改用B计划。

6. 计划B: 用yum卸载再安装

可以预料,这个计划要多折腾一些。仍然需要在超级管理员root的权限下运行下面的命令。

6.1 停止web服务器

这时为了避免用户访问网站时,看到数据库连接失败这样的错误信息。到这时我才想起这一点来,还是对用户关怀不够,应该在有可能宕掉网站的操作之前就做的。

因为使用的是Nginx,所以运行下面的命令:

# service nginx stop
Stopping nginx: [ OK ]

6.2 卸载MySQL 5.5.28

一共有3个包要卸载。

先卸载mysql-server包:

# yum remove mysql mysql-server
Dependencies Resolved

================================================================================
 Package            Arch         Version                  Repository       Size
================================================================================
Removing:
 MySQL-server       x86_64       5.5.28-1.linux2.6        installed       153 M

Transaction Summary
================================================================================
Remove        1 Package(s)

Installed size: 153 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Erasing    : MySQL-server-5.5.28-1.linux2.6.x86_64                        1/1
  Verifying  : MySQL-server-5.5.28-1.linux2.6.x86_64                        1/1

Removed:
  MySQL-server.x86_64 0:5.5.28-1.linux2.6

Complete!

再卸载mysql-client:

# yum remove mysql-client
Dependencies Resolved

================================================================================
 Package            Arch         Version                  Repository       Size
================================================================================
Removing:
 MySQL-client       x86_64       5.5.28-1.linux2.6        installed        57 M

Transaction Summary
================================================================================
Remove        1 Package(s)

Installed size: 57 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : MySQL-client-5.5.28-1.linux2.6.x86_64                        1/1
  Verifying  : MySQL-client-5.5.28-1.linux2.6.x86_64                        1/1

Removed:
  MySQL-client.x86_64 0:5.5.28-1.linux2.6

Complete!
View Code

最后卸载mysql-devel:

# yum remove mysql-devel
Dependencies Resolved

================================================================================
 Package           Arch         Version                   Repository       Size
================================================================================
Removing:
 MySQL-devel       x86_64       5.5.28-1.linux2.6         installed        20 M

Transaction Summary
================================================================================
Remove        1 Package(s)

Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : MySQL-devel-5.5.28-1.linux2.6.x86_64                         1/1
  Verifying  : MySQL-devel-5.5.28-1.linux2.6.x86_64                         1/1

Removed:
  MySQL-devel.x86_64 0:5.5.28-1.linux2.6

Complete!
View Code

3个包的卸载都顺利完成。

6.3 安装MySQL 5.6.19

安装比卸载更简单,因为yum会自动检查依赖安装包:

# yum install mysql-server
Dependencies Resolved

================================================================================
 Package                   Arch      Version         Repository            Size
================================================================================
Installing:
 mysql-community-server    x86_64    5.6.19-2.el6    mysql56-community     52 M
Installing for dependencies:
 mysql-community-client    x86_64    5.6.19-2.el6    mysql56-community     18 M
 mysql-community-common    x86_64    5.6.19-2.el6    mysql56-community    298 k
 mysql-community-libs      x86_64    5.6.19-2.el6    mysql56-community    1.9 M

Transaction Summary
================================================================================
Install       4 Package(s)

Total size: 72 M
Installed size: 323 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-common-5.6.19-2.el6.x86_64                   1/4
  Installing : mysql-community-libs-5.6.19-2.el6.x86_64                     2/4
  Installing : mysql-community-client-5.6.19-2.el6.x86_64                   3/4
  Installing : mysql-community-server-5.6.19-2.el6.x86_64                   4/4
warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
/bin/chmod: cannot access `': No such file or directory
  Verifying  : mysql-community-common-5.6.19-2.el6.x86_64                   1/4
  Verifying  : mysql-community-libs-5.6.19-2.el6.x86_64                     2/4
  Verifying  : mysql-community-client-5.6.19-2.el6.x86_64                   3/4
  Verifying  : mysql-community-server-5.6.19-2.el6.x86_64                   4/4

Installed:
  mysql-community-server.x86_64 0:5.6.19-2.el6

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.19-2.el6
  mysql-community-common.x86_64 0:5.6.19-2.el6
  mysql-community-libs.x86_64 0:5.6.19-2.el6

Complete!

由于篇幅关系,输出有所缩略。一切顺利,继续!

预告:繁琐的事情这才开始。

6.4 更改MySQL配置,来使用数据硬盘

更改\etc\my.cnf,下面只列出更改的相关设置:

[mysqld]
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
# data path changed to 2nd physical hard disk /dev/xvdb after upgrading from MySQL 5.5 to MySQL 5.6
innodb_data_home_dir = /data/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
datadir = /data/mysql

如果你也更改了数据目录,最后一行的 datadir = /data/mysql 切不可遗漏,我就是因为这一行实际上没有及时改,还是指向旧的数据目录,导致数据升级失败,直到升级数据之后才发现,在下文中有详细论述。

6.5 启动MySQL服务

启动服务:

# service mysql start
mysql: unrecognized service

居然出错了!只好直接运行MySQL的daemon:

# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]

后来才知道,mysql是MySQL 5.5的服务名称,到了MySQL 5.6服务就改名为mysqld了。所以,其实这里可以运行service mysqld start的。

6.6 升级MySQL数据库及表

按照参考资料[6],到这时,MySQL的程序已经升级完毕,要升级数据了。

先把旧数据目录下的所有文件都拷贝到新的数据目录下。可惜,这里的命令在我的工作日志中没有记录,日后找到再不上。不过这是基本的Linux命令,就算你不知道,也一定能在网上找到。

然后运行下面的命令:

# mysql_upgrade -uroot -p
Enter password:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck' with connection arguments: '--port=<为安全故略去>' '--socket=/var/lib/mysql/mysql.sock'
Warning: Using a password on the command line interface can be insecure.
Running 'mysqlcheck' with connection arguments: '--port=<为安全故略去>' '--socket=/var/lib/mysql/mysql.sock'
Warning: Using a password on the command line interface can be insecure.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
# ... ... 为省略篇幅故略去 ... ...
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Running 'mysql_fix_privilege_tables'...
Warning: Using a password on the command line interface can be insecure.
Running 'mysqlcheck' with connection arguments: '--port=<为安全故略去>' '--socket=/var/lib/mysql/mysql.sock'
Warning: Using a password on the command line interface can be insecure.
Running 'mysqlcheck' with connection arguments: '--port=<为安全故略去>' '--socket=/var/lib/mysql/mysql.sock'
Warning: Using a password on the command line interface can be insecure.
mydb.table1                                         OK
mydb.table2                                         OK
# ... ... 为省略篇幅故略去 ... ...
mydb.table793                                       OK
mydb.table794                                       OK
OK

到这里发现,数据库有问题,数据升级并未成功。原因就是之前提及的,升级数据时\etc\my.cnf中的数据目录(即datadir = 这一行)还是指向旧的数据目录,我猜想这导致一些操作发生了混乱。

这时我感觉到难免的慌张和混乱,之后我做了一些尝试:

  • 重复升级数据的过程,结果依旧
  • 尝试修复缺失或者损毁的系统数据库中的5个数据表,结果发现文档犹如进入了一个迷宫,不得要领。

不得不就此作罢。

6.7 重新创建数据目录

看起来由于我之前的疏忽,数据库已经在上一步升级数据中被损毁了!

这时候,你能做什么!谷歌(或者百度)就是你当前最好的朋友!

在冒汗和揪头发的折磨中,总算找到了根救命稻草mysql_install_db,详见参考资料[9],这个命令可以重新创建数据目录,这就意味着重新创建系统数据库mysql,也意味着现有的用户数据库都将被清除。这时,你会感谢上帝、佛祖、圣母和玉皇大帝,如果你在最开始对所有的数据库做了备份的话。回头看一下我们在5.1 备份所有的数据库做的事情,就知道这是多么重要了!有了备份,我们就可以恢复所有的数据库了!

先要做的,是在MySQL的配置文件中设置正确的数据目录。再次更改\etc\my.cnf,下面只列出更改的相关设置:

[mysqld]
datadir = /data/mysql

然后,祭出我们的救命稻草mysql_install_db来重新创建数据目录(如果你想知道该命令的详细参数,可见参考资料[9]):

# /usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2014-06-13 00:35:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-06-13 00:35:17 11574 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-06-13 00:35:17 11574 [Note] InnoDB: The InnoDB memory heap is disabled
2014-06-13 00:35:17 11574 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-06-13 00:35:17 11574 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-06-13 00:35:17 11574 [Note] InnoDB: Using Linux native AIO
2014-06-13 00:35:17 11574 [Note] InnoDB: Using CPU crc32 instructions
2014-06-13 00:35:17 11574 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-06-13 00:35:17 11574 [Note] InnoDB: Completed initialization of buffer pool
2014-06-13 00:35:17 11574 [Note] InnoDB: Highest supported file format is Barracuda.
2014-06-13 00:35:17 11574 [Note] InnoDB: 128 rollback segment(s) are active.
2014-06-13 00:35:17 11574 [Note] InnoDB: Waiting for purge to start
2014-06-13 00:35:17 11574 [Note] InnoDB: 5.6.19 started; log sequence number 44199093
2014-06-13 00:35:17 11574 [Warning] InnoDB: Cannot open table mysql/innodb_table_stats from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
ERROR: 1146  Table 'mysql.innodb_table_stats' doesn't exist
2014-06-13 00:35:17 11574 [ERROR] Aborting

2014-06-13 00:35:17 11574 [Note] Binlog end
2014-06-13 00:35:18 11574 [Note] InnoDB: FTS optimize thread exiting.
2014-06-13 00:35:18 11574 [Note] InnoDB: Starting shutdown...
2014-06-13 00:35:19 11574 [Note] InnoDB: Shutdown completed; log sequence number 44199103
2014-06-13 00:35:19 11574 [Note] /usr/sbin/mysqld: Shutdown complete

又出错了!别慌,这是因为数据目录并未清空,其中还有之前损毁的数据库文件。

删除当前的数据目录。我实际做的是把 /data/mysql 改名为 /data/mysql.bak2,效果一样,/data/mysql 目录不存在了,只是我做了个物理文件备份。

再次重建数据目录:

# /usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2014-06-13 00:46:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-06-13 00:46:06 11654 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-06-13 00:46:06 11654 [Note] InnoDB: The InnoDB memory heap is disabled
2014-06-13 00:46:06 11654 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-06-13 00:46:06 11654 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-06-13 00:46:06 11654 [Note] InnoDB: Using Linux native AIO
2014-06-13 00:46:06 11654 [Note] InnoDB: Using CPU crc32 instructions
2014-06-13 00:46:06 11654 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-06-13 00:46:06 11654 [Note] InnoDB: Completed initialization of buffer pool
2014-06-13 00:46:06 11654 [Note] InnoDB: The first specified data file /data/mysql/ibdata1 did not exist: a new database to be created!
2014-06-13 00:46:06 11654 [Note] InnoDB: Setting file /data/mysql/ibdata1 size to 12 MB
2014-06-13 00:46:06 11654 [Note] InnoDB: Database physically writes the file full: wait...
2014-06-13 00:46:06 11654 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-06-13 00:46:07 11654 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-06-13 00:46:09 11654 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-06-13 00:46:09 11654 [Warning] InnoDB: New log files created, LSN=45781
2014-06-13 00:46:09 11654 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-06-13 00:46:09 11654 [Note] InnoDB: Doublewrite buffer created
2014-06-13 00:46:09 11654 [Note] InnoDB: 128 rollback segment(s) are active.
2014-06-13 00:46:09 11654 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-06-13 00:46:09 11654 [Note] InnoDB: Foreign key constraint system tables created
2014-06-13 00:46:09 11654 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-06-13 00:46:09 11654 [Note] InnoDB: Tablespace and datafile system tables created.
2014-06-13 00:46:09 11654 [Note] InnoDB: Waiting for purge to start
2014-06-13 00:46:09 11654 [Note] InnoDB: 5.6.19 started; log sequence number 0
2014-06-13 00:46:10 11654 [Note] Binlog end
2014-06-13 00:46:10 11654 [Note] InnoDB: FTS optimize thread exiting.
2014-06-13 00:46:10 11654 [Note] InnoDB: Starting shutdown...
2014-06-13 00:46:12 11654 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2014-06-13 00:46:12 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-06-13 00:46:12 11678 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-06-13 00:46:12 11678 [Note] InnoDB: The InnoDB memory heap is disabled
2014-06-13 00:46:12 11678 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-06-13 00:46:12 11678 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-06-13 00:46:12 11678 [Note] InnoDB: Using Linux native AIO
2014-06-13 00:46:12 11678 [Note] InnoDB: Using CPU crc32 instructions
2014-06-13 00:46:12 11678 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-06-13 00:46:12 11678 [Note] InnoDB: Completed initialization of buffer pool
2014-06-13 00:46:12 11678 [Note] InnoDB: Highest supported file format is Barracuda.
2014-06-13 00:46:12 11678 [Note] InnoDB: 128 rollback segment(s) are active.
2014-06-13 00:46:12 11678 [Note] InnoDB: Waiting for purge to start
2014-06-13 00:46:12 11678 [Note] InnoDB: 5.6.19 started; log sequence number 1625977
2014-06-13 00:46:12 11678 [Note] Binlog end
2014-06-13 00:46:12 11678 [Note] InnoDB: FTS optimize thread exiting.
2014-06-13 00:46:12 11678 [Note] InnoDB: Starting shutdown...
2014-06-13 00:46:14 11678 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

后面还有一些输出,只是一些说明,关于如何准备MySQL的服务、如何设置管理员密码、等等。

好了,到这里,看起来总算恢复都正常了。

继续,设置管理员密码:

# mysqladmin -u root password '********'

6.8 恢复用户数据库

这时,只是重建了系统数据库mysql,原先的用户数据库都没了。要先创建(空的)用户数据库,然后从备份恢复。

进入MySQL命令行:

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.19 MySQL Community Server (GPL)

再创建用户数据库:

mysql> CREATE DATABASE `mydb`;
Query OK, 1 row affected (0.00 sec)
mysql> exit
Bye

这时,mydb数据库还是空的。从之前的数据库备份恢复mydb:

# mysql -u root -p mydb < 2014-06-12_mydb.sql
Enter password:

用户数据库顺利恢复。

6.9 设置服务(daemon)在机器启动时启动

开启mysqld服务的开机启动状态:

# chkconfig mysqld on

再查看:

# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

正确!继续。

6.10 重启web服务器

对应于6.1 停止web服务器,我们要再次开启网站、允许用户访问了:

# service nginx start
Starting nginx:                                            [  OK  ]

测试网站,一切正常!

6.11 修改CakePHP中数据库连接的设置

其实网站还有点儿小问题,不过这和MySQL升级无关,只是作为完整的实际过程,记录在这里。

实际上这时还是无法访问网站的,访问网站主页时遇到下面的错误:

2014-06-13 01:07:23 Warning: Warning (2): mysql_connect() [<a href='http://php.net/function.mysql-connect'>function.mysql-connect</a>]: No such file or directory in [/usr/share/nginx/.../cake/libs/model/datasources/dbo/dbo_mysql.php, line 561]

根据参考资料[11],修改CakePHP 1.3代码中的app/config/database.php:

class DATABASE_CONFIG {
    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'username',
        'password' => 'password',
        'database' => 'mydb',
        'prefix' => ''
        ,'encoding' => 'utf8'
        ,'port' => '/data/mysql/mysql.sock'
    );

如上所示,增加了port的设置。注意,这只适用于*nix系统,Windows上是不需要这样的。另,CakePHP 2.x的设置与此略有不同,请参考相关文档。

这样网站就能正常访问了。

A. 参考资料

  1. 阿里云,盛大云安装LUM 硬盘加载方法说明
    http://www.zijidelu.org/thread-47267-1-1.html
  2. 阿里云新购买的linux数据盘,加载方法
    http://blog.sina.com.cn/s/blog_467eb8ca0101mniu.html
  3. ext3 or ext4 how to check which one am using?
    http://ubuntuforums.org/showthread.php?t=1284789
  4. 在阿里云Linux服务器上安装MySQL
    http://www.blogjava.net/amigoxie/archive/2013/02/22/395605.html
  5. Basic Yum Commands and how to use them
    http://yum.baseurl.org/wiki/YumCommands
  6. Using the MySQL Yum Repository :: 3 Upgrading MySQL with the MySQL Yum Repository
    http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/updating-yum-repo.html
  7. [研究] MySQL Community 5.6.15 版安裝(yum) (CentOS 6.5 x64)
    http://shaurong.blogspot.sg/2014/01/mysql-community-5615-tgz-centos-65-x64.html
  8. How to upgrade MySQL 5.5 to MySQL 5.6 on CentOS 6.3/Red-hat/Fedora
    http://opensourcedbms.com/dbms/how-to-upgrade-mysql-5-5-to-mysql-5-6-on-centos-6-3-red-hat-fedora/
  9. MySQL 5.6 Reference Manual :: 4.4.3 mysql_install_db — Initialize MySQL Data Directory
    http://dev.mysql.com/doc/refman/5.6/en/mysql-install-db.html
  10. mysql_install_db: How to set the root password
    http://dba.stackexchange.com/questions/31308/mysql-install-db-how-to-set-the-root-password
  11. CakePHP: No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)
    http://stackoverflow.com/questions/3968013/cakephp-no-such-file-or-directory-trying-to-connect-via-unix-var-mysql-mysq
posted @ 2014-08-02 03:34  Black Puppy  阅读(13790)  评论(7编辑  收藏  举报