MySQL Migration Upgrade Solution

Background task


MySQL Migration Upgrade Solution


As the existing business structure has been unable to meet current business requirements, ensure data integrity under the premise, you are required to migrate existing databases to a separate server In addition, in the case of normal service to ensure that the original, the original LAMP mysql database environment upgraded to version 5.6.31 5.6.35.

Mission requirements

Zhengzhou infertility hospital: http: //jbk.39.net/yiyuanzaixian/zztjyy//

1. In the service maintenance time (02: 00-4: 00) segment of the database full backup

2. MySQL database migration from the old server to the new server and upgraded version 5.6.35

Task dismantling

1. New Server Installation Centos7.5, and install the MySQL-5.6.35 version of the database

2. Stop control, front-end applications to stop, stop the MySQL database

3. The standby database (omitted)

4. Database Migration -> synchronize database files to the new environment (rsync / scp)

5. Verify test

Task Solutions

Environment Description

MySQL Migration Upgrade Solution


Specific steps

1. Stop the appropriate service old environment

1) Stop monitor slightly 2) stop the apache service applications and databases [root @ lamp ~] # service httpd stop [root @ lamp ~] # service mysql stopShutting down MySQL .. SUCCESS!

2. The new deployment environment Installing MySQL

① official website to download the software mysql

# du -sh mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz301M mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

② installation requirements

Installation directory (basedir): / usr / local / mysql database directory (datadir): / usr / local / mysql / data port: 3306socket file: /tmp/mysql.sock error log file: / usr / local / mysql / data / mysql.err

Installation procedure ③ glibc

1) extract the package

# tar -xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz# cd /usr/local/# ln -s /soft/×××taller/mysql-5.6.35-linux-glibc2.5-x86_64 mysql注意:进入到/usr/local目录里软连接

2) 创建用户并修改目录权限

1. 查看用户是否存在[root@db01 mysql]# id mysqlid: mysql: no such user[root@db01 mysql]# useradd -r -s /sbin/nologin mysql[root@db01 mysql]# id mysqluid=997(mysql) gid=995(mysql) 组=995(mysql)2. 更改mysql的安装目录的权限[root@db01 mysql]# chown -R mysql.mysql /usr/local/mysql/[root@db01 mysql]# ll -d /usr/local/mysql/drwxr-xr-x 13 mysql mysql 191 10月 9 10:26 /usr/local/mysql/

3) 修改配置文件

修改/etc/my.cnf文件[root@db01 mysql]# vim /etc/my.cnf[mysqld]basedir=/usr/local/mysqldatadir=/usr/local/mysql/dataport=3307socket=/usr/local/mysql/mysql.socklog-error=/usr/local/mysql/data/mysql3307.err

4) 拷贝启动脚本

[root@db01 mysql]# pwd/usr/local/mysql[root@db01 mysql]# cp support-files/mysql.server /etc/init.d/mysql

5) 初始化说明

1. 正常安装新数据库直接使用,是需要初始化数据库然后再启动使用

2. 当前需求是将原来MySQL数据库文件迁移到新的数据库的数据目录里,故不需要初始化

3. 迁移数据库到新环境

说明:新数据库服务器上操作

① 同步老库数据文件到新库数据目录里

[root@db01 mysql]# rsync -av 10.1.1.1:/usr/local/mysql/data/ /usr/local/mysql/data

② 启动新数据库

直接启动新的数据库,并且检查日志文件(查看是否有选项不兼容)[root@db01 mysql]# service mysql start

③ 升级数据库(重点,升级数据库文件)

使用mysql_upgrade命令检查数据文件的兼容性[root@db01 ~]# /usr/local/mysql/bin/mysql_upgrade -S /tmp/mysql.sock -p123注意:1. 在实际的环境中,建议使用-s参数,不检查业务表,只检查系统文件2. 升级是需要连接数据库的,-p密码 -S指定socket文件[root@db01 mysql]# /usr/local/mysql/bin/mysql_upgrade -pEnter password:Looking for 'mysql' as: /usr/local/mysql/bin/mysqlLooking for 'mysqlcheck' as: /usr/local/mysql/bin/mysqlcheckError: Failed while fetching Server version! Could be due to unauthorized access.FATAL ERROR: Upgrade failed原因:连接数据库失败

4. 原web服务连接新数据库(LAMP=>LNMP)

① 修改php连接mysql的配置文件(如果有)

[root@lamp ~]# find / -name php.ini/usr/local/lib/php.ini[root@lamp ~]# vim /usr/local/lib/php.ini[MySQL]mysql.default_port = 3306mysql.default_host = 10.1.1.37[MySQLi]mysql.default_port = 3306mysql.default_host = 10.1.1.37

② 修改网站配置文件连接数据库

修改www.myblog.net网站所在数据库目录的配置文件[root@lamp www]# pwd/var/html/www[root@lamp www]# vim wp-config.php...// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** ///** WordPress数据库的名称 */define('DB_NAME', 'myblog');/** MySQL数据库用户名 */define('DB_USER', 'root');/** MySQL数据库密码 */define('DB_PASSWORD', '123');/** MySQL主机 */define('DB_HOST', '10.1.1.37');/** 创建数据表时默认的文字编码 */define('DB_CHARSET', 'utf8');

③ 新数据库授权为web服务

The new mysql database requires authorization to [email protected] user mysql> grant all on * * to 'root'@'10.1.1.19' identified by '123';. Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) Note: firewalld firewall and selinux all closed down, or killing are not connected!

④ start web service

[root@lamp ~]# service apache start[root@lamp ~]# netstat -nltp|grep httpdtcp 0 0 :::80 :::* LISTEN 1376/httpd

⑤ verification test

1. Use a browser to access a remote access tool mysql [root @ lamp ~] on server 2. web # mysql -uroot -h10.1.1.37 -uroot -p123

Learning Resources:

Tian Fun  MySQL

https://pan.baidu.com/s/1Cb1eGwb4dn45I4tbQ2Ggzg    extraction code: yfw6 

https://pan.baidu.com/s/1qXYYhcS    extraction code:  mkqu


Guess you like

Origin blog.51cto.com/14393794/2409399