mariadb的版本升级方法

mariadb的版本升级方法

一、简介

  二进制安装方式,升级版本相对简单可靠。本案例基于二进制安装方式进行升级演示。

  先完整的安装mariadb10.4版本,然后在此基础上升级到10.5版本。

二、Centos7.6最小化安装依赖包

yum install -y net-tools
yum install -y wget

#切换aliyun的yum源
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
# 重建源数据缓存 
yum clean all
yum makecache 

yum -y install vim-enhanced wget net-tools telnet vim lrzsz ntp
yum -y install lshw pciutils gdisk system-storage-manager 
yum -y install bash-completion zip unzip bzip2 tree tmpwatch pinfo man-pages
yum -y install nano vim-enhanced tmux screen
yum -y install net-tools psmisclsof sysstat
yum -y install yum-plugin-security yum-utils createrepo
yum -y install get wget curl eliks lynx lftp mailx mutt reync 
yum -y install libaio make cmake gcc-c++ gcc zib zlib-devel open openssl-devel pcre pcre-devel

三、创建用户

useradd -M -r -s  /bin/nologin mysql
echo "mysql"|passwd --stdin mysql

四、下载安装

wget https://downloads.mariadb.org/interstitial/mariadb-10.4.11/bintar-linux-systemd-x86_64/mariadb-10.4.11-linux-systemd-x86_64.tar.gz/from/http%3A//mariadb.mirror.nucleus.be/
tar -zxvf mariadb-10.4.11-linux-systemd-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mariadb-10.4.11-linux-systemd-x86_64/ mysql
echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh

五、配置文件

cat >/etc/my.cnf<<"EOF"
[client]
port    = 3306
socket    = /data/mysql/data/mysql.sock
default-character-set=utf8mb4

[mysql]
prompt="\u@MariaDB0 \R:\m:\s [\d]> "
no-auto-rehash
default-character-set=utf8mb4

[mysqld]
user    = mysql
port    = 3306
extra_port=13306
socket  = /data/mysql/data/mysql.sock
basedir= /usr/local/mysql
datadir= /data/mysql/data
log-error=/data/mysql/logs/mysql-error.log
pid-file=/data/mysql/data/mariadb.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 0.1
log_queries_not_using_indexes =1
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
server-id = 3306
log-bin = /data/mysql/logs/mybinlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
expire_logs_days = 30
log_slave_updates
binlog_format = row
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
lock_wait_timeout = 3600
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30

transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 5734M
innodb_buffer_pool_instances = 8
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2

# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 8000
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 1
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
#innodb_checksums = 1
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_stats_on_metadata = 0
symbolic-links=0
innodb_status_file = 1

#performance_schema
performance_schema = 1

# 字符集设定utf8mb4
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'

# 优化
optimizer_switch = "mrr=on,mrr_cost_based=on,mrr_sort_keys=on"
deadlock_search_depth_short = 3 
deadlock_search_depth_long = 10 
deadlock_timeout_long = 10000000 
deadlock_timeout_short = 5000
slave-parallel-threads=8

# gtid
gtid_strict_mode=1
wsrep_gtid_mode=1

[mysqld_safe]
nice=-19
open-files-limit=65535

[mysqldump]
quick
max_allowed_packet = 64M

EOF

SERVIER_ID=`date +%S`
sed -i "s/server-id = 3306/server-id = 3306"${SERVIER_ID}"/" /etc/my.cnf
my.cnf

六、修改文件权限

mkdir -p /data/mysql/{data,logs}
chown mysql.mysql -R /data/mysql
chown mysql.mysql -R /usr/local/mariadb-10.4.11-linux-systemd-x86_64/
chown mysql.mysql -R /usr/local/mysql

七、初始化

cd /usr/local/mysql
./scripts/mysql_install_db  --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

八、启动关闭服务

# 启动mariadb
ls /usr/local/mysql/support-files/systemd/
cp support-files/systemd/mariadb.service /lib/systemd/system/
systemctl daemon-reload
systemctl start mariadb

# 关闭maridb
systemctl stop mariadb

九、登录验证

# 登录,初次登陆,免密码
[root@db138 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.4.11-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@MariaDB0 17:45:  [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.001 sec)

root@MariaDB0 17:45:  [(none)]> 

delete from mysql.user where user='';
drop database test;
grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'root' with grant option;

# 关闭maridb
systemctl stop mariadb
View Code

十、升级操作

# 关闭maridb
systemctl stop mariadb

# 登录,初次登陆,免密码
[root@db138 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.4.11-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@MariaDB0 17:45:  [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.001 sec)

root@MariaDB0 17:45:  [(none)]> 

delete from mysql.user where user='';
drop database test;
grant all privileges on *.* to 'root'@'127.0.0.1' identified by 'root' with grant option;

# 关闭maridb
systemctl stop mariadb

# 备份目录
cd /data/mysql/
zip -r data_old.zip data

# 解压新版
cd /opt/
wget http://mariadb.mirror.nucleus.be//mariadb-10.5.0/bintar-linux-systemd-x86_64/mariadb-10.5.0-linux-systemd-x86_64.tar.gz
tar -zxf /opt/mariadb-10.5.0-linux-systemd-x86_64.tar.gz -C /usr/local/
unlink mysql
ln -s mariadb-10.5.0-linux-systemd-x86_64/ mysql
chown -R mysql.mysql mariadb-10.5.0-linux-systemd-x86_64/
chown -R mysql.mysql mysql

cd mysql/
cp support-files/systemd/mariadb.service /lib/systemd/system/ # 覆盖原来的文件
systemctl daemon-reload
systemctl start mariadb




[root@db138 mysql]# mysql_upgrade -s
The --upgrade-system-tables option was used, user tables won't be touched.
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.column_stats                                 OK
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.global_priv                                  OK
mysql.gtid_slave_pos                               OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.index_stats                                  OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.roles_mapping                                OK
mysql.servers                                      OK
mysql.table_stats                                  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.transaction_registry                         OK
Phase 2/7: Installing used storage engines... Skipped
Phase 3/7: Fixing views... Skipped
Phase 4/7: Running 'mysql_fix_privilege_tables'
Phase 5/7: Fixing table and database names ... Skipped
Phase 6/7: Checking and upgrading tables... Skipped
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK
[root@db138 mysql]# 
[root@db138 mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.5.0-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@MariaDB0 17:57:  [(none)]> 

# 升级完毕
升级版本
posted @ 2020-01-02 17:03  davie2020  阅读(7111)  评论(0编辑  收藏  举报