在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月12日进行的,到今天才有空做个记录,便于日后参考。 动手之前,查找了很多资料,因为MySQL要比之前升级的Git和Nginx要复杂多了。我在参考资料中列出了我所能找到作为依据的文档,可供参考。 2. 计划 我们使用的服务器是阿里云的,服务器的操作系统是CentOS 6.3。登录管理界面,发现共有两块物理硬盘,一块系统盘,一块数据盘,而我们只使用了系统盘,数据盘一直空着没用。所以,计划就变成: 1.加载数据硬盘 2.升级MySQL的同时,迁移MySQL数据到数据硬盘上。 3. 加载数据硬盘 下面的操作需要以超级管理员root的身份登录服务器进行操作。 3.1 查看硬盘 首先,查看硬盘使用情况: # fdisk -lDisk /dev/xvda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000 Device Boot Start End Blocks Id System/dev/xvda1 * 1 2550 20480000 83 Linux/dev/xvda2 2550 2611 490496 82 Linux swap / SolarisDisk /dev/xvdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000# df -hFilesystem 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/xvdbmke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1310720 inodes, 5242880 blocks262144 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000Writing inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 24 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override. 格式化顺利完成。 3.3 加载数据硬盘 下面,加载第二块物理硬盘为/data目录: # mount /dev/xvdb /data 这个命令没有反馈,当时我有点儿吃惊和失落。因为这许多命令我也都是第一次从网上查到,第一次使用,对于它们的输出和结果,都有一种第一次坐过山车般的期待、兴奋、好奇和不确定,每一次的输出对于我都是新的,你不知道翻过面前这个坡之后会出现什么! 再用下面的命令查看新的逻辑盘: # df -khFilesystem 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 --versionmysql 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 ^mysqlmysql-community-release.noarch 其中,^mysql是指以mysql开头的安装包。 用下面的命令查看安装了的和可用的安装包: # yum info mysql-serverInstalled PackagesName : MySQL-ServerArch : x86_64Version : 5.5.28Release : 1.linux2.6Repo : installedAvailable PackagesName : mysql-serverArch : x86_64Version : 5.1.73Release : 3.el6_5Repo : updates 这里不知道为啥可用的安装包没有显示MySQL 5.6的。 检查可用的安装包: # yum check-update mysql-serverObsoleting Packagesmysql-community-client.x86_64 5.6.19-2.el6 mysql56-community MySQL-client.x86_64 5.5.28-1.linux2.6 installedmysql-community-devel.x86_64 5.6.19-2.el6 mysql56-community MySQL-devel.x86_64 5.5.28-1.linux2.6 installedmysql-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-serverDependencies 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.6Installing 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 MTransaction Summary================================================================================Install 4 Package(s) 后面的输出省略了。可见有4个安装包(共70多MB)要下载、安装。结果,下载用了80分钟。 但安装遇到问题了: Running rpm_check_debugRunning Transaction TestTransaction 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)64Error 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-serverDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Removing: MySQL-server x86_64 5.5.28-1.linux2.6 installed 153 MTransaction Summary================================================================================Remove 1 Package(s)Installed size: 153 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionWarning: 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/1Removed: MySQL-server.x86_64 0:5.5.28-1.linux2.6Complete! 再卸载mysql-client: # yum remove mysql-clientDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Removing: MySQL-client x86_64 5.5.28-1.linux2.6 installed 57 MTransaction Summary================================================================================Remove 1 Package(s)Installed size: 57 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning 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/1Removed: MySQL-client.x86_64 0:5.5.28-1.linux2.6Complete! 最后卸载mysql-devel: # yum remove mysql-develDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Removing: MySQL-devel x86_64 5.5.28-1.linux2.6 installed 20 MTransaction Summary================================================================================Remove 1 Package(s)Installed size: 20 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning 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/1Removed: MySQL-devel.x86_64 0:5.5.28-1.linux2.6Complete! 3个包的卸载都顺利完成。 6.3 安装MySQL 5.6.19 安装比卸载更简单,因为yum会自动检查依赖安装包: # yum install mysql-serverDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Installing: mysql-community-server x86_64 5.6.19-2.el6 mysql56-community 52 MInstalling 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 MTransaction Summary================================================================================Install 4 Package(s)Total size: 72 MInstalled size: 323 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning 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/4warning: /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/4Installed: mysql-community-server.x86_64 0:5.6.19-2.el6Dependency 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.el6Complete! 由于篇幅关系,输出有所缩略。一切顺利,继续! 预告:繁琐的事情这才开始。 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.6innodb_data_home_dir = /data/mysql#innodb_data_file_path = ibdata1:10M:autoextend#innodb_log_group_home_dir = /var/lib/mysqldatadir = /data/mysql 如果你也更改了数据目录,最后一行的 datadir = /data/mysql 切不可遗漏,我就是因为这一行实际上没有及时改,还是指向旧的数据目录,导致数据升级失败,直到升级数据之后才发现,在下文中有详细论述。 6.5 启动MySQL服务 启动服务: # service mysql startmysql: unrecognized service 居然出错了!只好直接运行MySQL的daemon: # /etc/init.d/mysqld startStarting mysqld: [ OK ] 后来才知道,mysql是MySQL 5.5的服务名称,到了MySQL 5.6服务就改名为mysqld了。所以,其实这里可以运行service mysqld start的。 6.6 升级MySQL数据库及表 按照参考资料[6],到这时,MySQL的程序已经升级完毕,要升级数据了。 先把旧数据目录下的所有文件都拷贝到新的数据目录下。可惜,这里的命令在我的工作日志中没有记录,日后找到再不上。不过这是基本的Linux命令,就算你不知道,也一定能在网上找到。 然后运行下面的命令: # mysql_upgrade -uroot -pEnter password:Looking for 'mysql' as: mysqlLooking for 'mysqlcheck' as: mysqlcheckRunning '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 OKmysql.db OKmysql.event OKmysql.func OK# ... ... 为省略篇幅故略去 ... ...mysql.time_zone_transition OKmysql.time_zone_transition_type OKmysql.user OKRunning '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 OKmydb.table2 OK# ... ... 为省略篇幅故略去 ... ...mydb.table793 OKmydb.table794 OKOK 到这里发现,数据库有问题,数据升级并未成功。原因就是之前提及的,升级数据时/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/mysqlInstalling 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 pages2014-06-13 00:35:17 11574 [Note] InnoDB: The InnoDB memory heap is disabled2014-06-13 00:35:17 11574 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-06-13 00:35:17 11574 [Note] InnoDB: Compressed tables use zlib 1.2.32014-06-13 00:35:17 11574 [Note] InnoDB: Using Linux native AIO2014-06-13 00:35:17 11574 [Note] InnoDB: Using CPU crc32 instructions2014-06-13 00:35:17 11574 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-06-13 00:35:17 11574 [Note] InnoDB: Completed initialization of buffer pool2014-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 start2014-06-13 00:35:17 11574 [Note] InnoDB: 5.6.19 started; log sequence number 441990932014-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 exist2014-06-13 00:35:17 11574 [ERROR] Aborting2014-06-13 00:35:17 11574 [Note] Binlog end2014-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 441991032014-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/mysqlInstalling 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 pages2014-06-13 00:46:06 11654 [Note] InnoDB: The InnoDB memory heap is disabled2014-06-13 00:46:06 11654 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-06-13 00:46:06 11654 [Note] InnoDB: Compressed tables use zlib 1.2.32014-06-13 00:46:06 11654 [Note] InnoDB: Using Linux native AIO2014-06-13 00:46:06 11654 [Note] InnoDB: Using CPU crc32 instructions2014-06-13 00:46:06 11654 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-06-13 00:46:06 11654 [Note] InnoDB: Completed initialization of buffer pool2014-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 MB2014-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 MB2014-06-13 00:46:07 11654 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2014-06-13 00:46:09 11654 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02014-06-13 00:46:09 11654 [Warning] InnoDB: New log files created, LSN=457812014-06-13 00:46:09 11654 [Note] InnoDB: Doublewrite buffer not found: creating new2014-06-13 00:46:09 11654 [Note] InnoDB: Doublewrite buffer created2014-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 created2014-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 start2014-06-13 00:46:09 11654 [Note] InnoDB: 5.6.19 started; log sequence number 02014-06-13 00:46:10 11654 [Note] Binlog end2014-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 1625977OKFilling 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 pages2014-06-13 00:46:12 11678 [Note] InnoDB: The InnoDB memory heap is disabled2014-06-13 00:46:12 11678 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-06-13 00:46:12 11678 [Note] InnoDB: Compressed tables use zlib 1.2.32014-06-13 00:46:12 11678 [Note] InnoDB: Using Linux native AIO2014-06-13 00:46:12 11678 [Note] InnoDB: Using CPU crc32 instructions2014-06-13 00:46:12 11678 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-06-13 00:46:12 11678 [Note] InnoDB: Completed initialization of buffer pool2014-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 start2014-06-13 00:46:12 11678 [Note] InnoDB: 5.6.19 started; log sequence number 16259772014-06-13 00:46:12 11678 [Note] Binlog end2014-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 1625987OK 后面还有一些输出,只是一些说明,关于如何准备MySQL的服务、如何设置管理员密码、等等。 好了,到这里,看起来总算恢复都正常了。 继续,设置管理员密码: # mysqladmin -u root password '********' 6.8 恢复用户数据库 这时,只是重建了系统数据库mysql,原先的用户数据库都没了。要先创建(空的)用户数据库,然后从备份恢复。 进入MySQL命令行: # mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 7Server version: 5.6.19 MySQL Community Server (GPL) 再创建用户数据库: mysql> CREATE DATABASE `mydb`;Query OK, 1 row affected (0.00 sec)mysql> exitBye 这时,mydb数据库还是空的。从之前的数据库备份恢复mydb: # mysql -u root -p mydb < 2014-06-12_mydb.sqlEnter password: 用户数据库顺利恢复。 6.9 设置服务(daemon)在机器启动时启动 开启mysqld服务的开机启动状态: # chkconfig mysqld on 再查看: # chkconfig --list mysqldmysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 正确!继续。 6.10 重启web服务器 对应于6.1 停止web服务器,我们要再次开启网站、允许用户访问了: # service nginx startStarting 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-mysql (责任编辑:IT) |