1.1 配置文件的默认读取位置
[root@db01 ~]# mysqld --help --verbose |grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
mysqld_safe --defaults-file=/opt/my.cnf &
1.2 配置文件结构
[root@db01 ~]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
socket=/tmp/mysql.sock
port=3306
[mysql]
socket=/tmp/mysql.sock
1.2.1 标签
[标签]
分类不通程序的参数.
服务标签: [mysqld] [mysqld_safe] [server]
客户端标签: [mysql] [mysqldump] [client]
1.2.2 配置项
具体配置
说明:
生产中,初始化数据库,需要加载配置文件进行.
例如
mysqld --defaluts-file=/opt/my.cnf --initialize-insecure …
2.2 测试环境
同版本
不同版本
2.3 同版本
2.3.1 准备目录
[root@db01 ~]# mkdir -p /data/330{7…9}/data
[root@db01 ~]# chown -R mysql. /data
2.3.2 配置文件
cat >/data/3307/my.cnf <
user=mysql
basedir=/usr/local/mysql
datadir=/data/3307/data
socket=/tmp/mysql3307.sock
port=3307
[mysql]
socket=/tmp/mysql3307.sock
EOF
cat >/data/3308/my.cnf <
user=mysql
basedir=/usr/local/mysql
datadir=/data/3308/data
socket=/tmp/mysql3308.sock
port=3308
[mysql]
socket=/tmp/mysql3308.sock
EOF
cat >/data/3309/my.cnf <
user=mysql
basedir=/usr/local/mysql
datadir=/data/3309/data
socket=/tmp/mysql3309.sock
port=3309
[mysql]
socket=/tmp/mysql3309.sock
EOF
2.2.3 初始化三份数据
mysqld --defaults-file=/data/3307/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307/data
mysqld --defaults-file=/data/3308/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3308/data
mysqld --defaults-file=/data/3309/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3309/data
2.2.4 启动测试
mysqld_safe --defaults-file=/data/3307/my.cnf &
mysqld_safe --defaults-file=/data/3308/my.cnf &
mysqld_safe --defaults-file=/data/3309/my.cnf &
mysql -S /tmp/mysql3307.sock
mysql -S /tmp/mysql3308.sock
mysql -S /tmp/mysql3309.sock
2.4 不同版本
2.4.1 上传解压
略.
2.4.2 软连接
ln -s /opt/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql56
ln -s /opt/mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql57
2.4.3 数据路径
mkdir -p /data/3356/data /data/3357/data
chown -R mysql.mysql /data
2.4.4 配置文件
cat >/data/3356/my.cnf <
user=mysql
basedir=/usr/local/mysql56
datadir=/data/3356/data
socket=/tmp/mysql3356.sock
port=3356
[mysql]
socket=/tmp/mysql3356.sock
EOF
cat >/data/3357/my.cnf <
user=mysql
basedir=/usr/local/mysql57
datadir=/data/3357/data
socket=/tmp/mysql3357.sock
port=3357
[mysql]
socket=/tmp/mysql3357.sock
EOF
2.4.5 初始化
/usr/local/mysql57/bin/mysqld --defaults-file=/data/3357/my.cnf --initialize-insecure
/usr/local/mysql56/scripts/mysql_install_db --defaults-file=/data/3356/my.cnf --user=mysql --basedir=/usr/local/mysql56 --datadir=/data/3356/data
2.4.6 启动
/usr/local/mysql57/bin/mysqld_safe --defaults-file=/data/3357/my.cnf &
/usr/local/mysql56/bin/mysqld_safe --defaults-file=/data/3356/my.cnf &
/usr/local/mysql56/bin/mysqld --defaults-file=/data/3356/my.cnf &
彩蛋:
user.frm —>表结构
user.MYD —>数据行
user.MYI —>索引
8.0之前 InnoDB表
t1.frm --> 表结构
t1.ibd --> 数据行+索引
升级
3.0 升级前准备知识
3.0.1 升级方式
a. inplace (就地升级)
适合于有主从环境.
b. merging (逻辑备份迁移升级)
3.0.2 升级注意事项(INPLACE)
来自于MySQL官网
Upgrade is only supported between General Availability (GA) releases.
Upgrade from MySQL 5.6 to 5.7 is supported. Upgrading to the latest release is recommended before upgrading to the next version. For example, upgrade to the latest MySQL 5.6 release before upgrading to MySQL 5.7.
Upgrade that skips versions is not supported. For example, upgrading directly from MySQL 5.5 to 5.7 is not supported.
Upgrade within a release series is supported. For example, upgrading from MySQL 5.7.x to 5.7.y is supported. Skipping a release is also supported. For example, upgrading from MySQL 5.7.x to 5.7.z is supported.
翻译:
a. 支持GA版本之间升级
b. 5.6–> 5.7 ,先将5.6升级至最新版,再升级到5.7
c. 5.5 —> 5.7 ,先将5.5 升级至最新,再5.5—> 5.6最新,再5.6—>5.7 最新
d. 回退方案要提前考虑好,最好升级前要备份(特别是往8.0版本升级)。
e. 降低停机时间(停业务的时间)
3.0.3 INPLACE 升级过程原理
0. 备份原数据库数据
a. 安装新版本软件
b. 关闭原数据库(挂维护页)
c. 使用新版本软件 “挂” 旧版本数据启动(–skip-grant-tables ,–skip-networking)
d. 升级 : 只是升级系统表。升级时间和数据量无关的。
e. 正常重启数据库。
f. 验证各项功能是否正常。
g. 业务恢复。
3.1 测试5.6.46 升级到5.7.30
a. 优雅(干净)的关闭5.6
mysql> set global innodb_fast_shutdown=0;
[root@db01 data]# /usr/local/mysql56/bin/mysqladmin -S /tmp/mysql3356.sock shutdown
b. 高版本挂低版本数据启动
[root@db01 data]# vim /data/3356/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql57
datadir=/data/3356/data
socket=/tmp/mysql3356.sock
port=3356
[mysql]
socket=/tmp/mysql3356.sock
[root@db01 ~]# /usr/local/mysql57/bin/mysqld_safe --defaults-file=/data/3356/my.cnf --skip-grant-tables --skip-networking &
c. 升级
[root@db01 ~]# /usr/local/mysql57/bin/mysql_upgrade -S /tmp/mysql3356.sock --force
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
c. 正常重启数据库
[root@db01 data]# /usr/local/mysql57/bin/mysqladmin -S /tmp/mysql3356.sock shutdown
[root@db01 data]# /usr/local/mysql57/bin/mysqld_safe --defaults-file=/data/3356/my.cnf &
3.1 Mysql 5.7.30 Inplace升级到MySQL 8.0.20
7.5.1 升级之前的预检查
a. 安装mysqlsh
[root@db01 opt]# tar xf mysql-shell-8.0.20-linux-glibc2.12-x86-64bit.tar.gz
[root@db01 opt]# ln -s /opt/mysql-shell-8.0.20-linux-glibc2.12-x86-64bit /usr/local/mysqlsh
[root@db01 opt]# cd /usr/local/mysqlsh/
[root@db01 bin]# vim /etc/profile
export PATH=/usr/local/mysqlsh/bin:$PATH
[root@db01 bin]# source /etc/profile
[root@db01 bin]# mysqlsh --version
mysqlsh Ver 8.0.20 for Linux on x86_64 - for MySQL 8.0.20 (MySQL Community Server (GPL))
b. 在5730数据库中创建链接用户
[root@db01 bin]# mysql -S /tmp/mysql3357.sock -uroot -p123
mysql> create user root@‘10.0.0.%’ identified with mysql_native_password by ‘123’;
mysql> grant all on . to root@‘10.0.0.%’;
c. 升级前检测
[root@db01 ~]# mysqlsh root:[email protected]:3357 -e “util.checkForServerUpgrade()” >>/tmp/up.log
7.5.2 正式升级
a. 安装 新版本软件 8.0.20
ok。
b. 停原库
连接到数据库中(5.7.30),执行以下语句。
mysql> set global innodb_fast_shutdown=0 ;
mysql> select @@innodb_fast_shutdown;
mysql> shutdown ;
c. 使用高版本软件(8.0.20)挂低版本(5.7.30)数据启动
[root@db01 opt]# vim /data/3357/my.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3357/data
socket=/tmp/mysql3357.sock
port=3357
default_authentication_plugin=mysql_native_password
[mysql]
socket=/tmp/mysql3357.sock
~
[root@db01 data]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3357/my.cnf --skip-grant-tables --skip-networking &
d. 重启数据库到正常状态
[root@db01 data]# mysqladmin -S /tmp/mysql3357.sock shutdown
[root@db01 data]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3357/my.cnf &