# Upgrading MySQL

> Upgrade from MySQL 5.6 to 5.7

Last edited by Junyangz AT 2018-05-18 19:44:46

**If you plan to to upgrade using the data directory from your existing:**

1. MySQL installation:
2. Stop the old (MySQL 5.6) server
3. Upgrade the MySQL binaries in place (replace the old binaries with the new ones)
4. Start the MySQL 5.7 server normally (no special options)
5. Run mysql\_upgrade to upgrade the system tables
6. Restart the MySQL 5.7 server

## Installing MySQL from Source

```bash
# refer MySQL-5.7 installation-tutorial.
```

## Backup old MySQL

```bash
#tar zcvf mysql.tar.gz /usr/local/mysql
service mysqld stop
cd /usr/local/
mv mysql mysql5.6
```

## Replace the binaries

```bash
#mv /usr/local/mysql-5.7.19 /usr/local/mysql
#ln -s  /usr/local/mysql/bin /usr/local/bin/
#unlink /usr/local/mysql
ln -s mysql-5.7.19/ mysql
chown -R mysql:mysql mysql-5.7.19/
chown -R mysql:mysql mysql
# copy init.d file
cp mysql/support-files/mysql.server  /etc/init.d/mysqld
```

## Set MySQL PATH

```bash
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

source /etc/profile
#echo $MYSQL_HOME
```

## Check and Upgrade MySQL Tables

```bash
service mysqld start
mysql/bin/mysql_upgrade -uroot -p -S /data2/mysql5.6/run/mysql.sock

mysql -uroot -p
show databases;
#database sys is MySQL5.7 new add.
#service mysqld restart
```

## Reference

* [MySQL Upgrade Strategies](https://dev.mysql.com/doc/refman/5.7/en/upgrading-strategies.html)
* [mysql\_upgrade](https://dev.mysql.com/doc/refman/5.7/en/mysql-upgrade.html)
* [MySQL 5.6升级至MySQL 5.7--------版本升级最佳实战](http://blog.51cto.com/lisea/1941616)
* [MySQL从5.6升级到5.7的多种实战经验总结](http://www.fordba.com/mysql-upgrade-from-56-to-57.html)
* [记录一次MySQL升级的运维实践](https://github.com/Junyangz/Documents/tree/46d56dc7cd9c671859be4e1e78b94b0bf252a739/Documentation/www.yunweipai.com/archives/24315.html)
