作者:俊达

我们在生产环境部署mysql时,一般很少使用RedHat Package Manager(RedHat软件包管理工具)。用rpm或或者其他包管理器安装mysql有其好处,例如安装简单,并且许多系统可能已经自带了某个版本的MySQL。

当然,使用RPM安装也存在一些缺点:

1、rpm依赖包的问题。如果删除线上机器的冲突包,可能引起其他软件运行异常。

2、多版本管理不方便。升级mysql或降级mysql不方便。无法多个版本同时运行。

3、单机多实例管理不方便。

但是,对于我们数据库管理员,需要掌握如何使用rpm包安装mysql。因为很可能需要处理用这种方式安装的mysql遇到的一些问题,如数据库无法启动、默认路径空间占满,需要将数据需要换到别的磁盘、调整参数等。

1 环境

CentOS 7.9

[root@box1 software]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core) [root@box1 software]# uname -a
Linux box1 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

2 RPM安装

2.1下载RPM安装包

到官网https://dev.mysql.com/downloads/mysql/下载社区版,历史版本点击“Archives”下载。

建议选择下载 RPM Bundle包,里面包含了需要的各个rpm包解压bundle包,可以看到里面的rpm包

# tar xf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar -C rpm/5.7/
# [root@box1 5.7]# ls -lh
总用量 1.1G
-rw-r--r--. 1 root root 518M 9月 25 2020 mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 26M 9月 25 2020 mysql-community-client-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 308K 9月 25 2020 mysql-community-common-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 3.8M 9月 25 2020 mysql-community-devel-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 46M 9月 25 2020 mysql-community-embedded-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 23M 9月 25 2020 mysql-community-embedded-compat-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 125M 9月 25 2020 mysql-community-embedded-devel-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2.4M 9月 25 2020 mysql-community-libs-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1.3M 9月 25 2020 mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 174M 9月 25 2020 mysql-community-server-5.7.32-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 120M 9月 25 2020 mysql-community-test-5.7.32-1.el7.x86_64.rpm

2.2安装rpm包

需要安装mysql-community-server, mysql-community-common, mysql-community-client, mysql-community-libs这些包

[root@box1 5.7]# rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm mysql-community-common-5.7.32-1.el7.x86_64.rpm mysql-community-server-5.7.32-1.el7.x86_64.rpm mysql-community-libs-5.7.32-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.32-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
mariadb-libs 被 mysql-community-libs-5.7.32-1.el7.x86_64 取代

2.3卸载冲突的包

安装报错,因为系统里已经安装了mariadb相关lib,需要先将这些lib卸载

[root@box1 5.7]# rpm -qa | grep maria
mariadb-devel-5.5.68-1.el7.x86_64
mariadb-libs-5.5.68-1.el7.x86_64 [root@box1 5.7]# rpm -evf mariadb-devel-5.5.68-1.el7.x86_64 mariadb-libs-5.5.68-1.el7.x86_64
错误:依赖检测失败:
libmysqlclient.so.18()(64bit) 被 (已安裝) net-snmp-agent-libs-1:5.7.2-49.el7.x86_64 需要
libmysqlclient.so.18()(64bit) 被 (已安裝) net-snmp-1:5.7.2-49.el7.x86_64 需要
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要
libmysqlclient.so.18()(64bit) 被 (已安裝) qt-mysql-1:4.8.7-8.el7.x86_64 需要
libmysqlclient.so.18()(64bit) 被 (已安裝) qt5-qtbase-mysql-5.9.7-4.el7.x86_64 需要
libmysqlclient.so.18()(64bit) 被 (已安裝) qt3-MySQL-3.3.8b-51.el7.x86_64 需要
libmysqlclient.so.18()(64bit) 被 (已安裝) MySQL-python-1.2.5-1.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) net-snmp-agent-libs-1:5.7.2-49.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) qt-mysql-1:4.8.7-8.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) qt5-qtbase-mysql-5.9.7-4.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) qt3-MySQL-3.3.8b-51.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) MySQL-python-1.2.5-1.el7.x86_64 需要
mysql-libs 被 (已安裝) net-snmp-1:5.7.2-49.el7.x86_64 需要 ### 加--nodeps强制卸载mariadb lib
[root@box1 5.7]# rpm -ev --nodeps mariadb-devel-5.5.68-1.el7.x86_64 mariadb-libs-5.5.68-1.el7.x86_64
软件包准备中...
mariadb-devel-1:5.5.68-1.el7.x86_64
mariadb-libs-1:5.5.68-1.el7.x86_64

卸载完mariadb lib包之后重新安装

[root@box1 5.7]# rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm mysql-community-common-5.7.32-1.el7.x86_64.rpm mysql-community-server-5.7.32-1.el7.x86_64.rpm mysql-community-libs-5.7.32-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.32-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.32-1.e################################# [ 25%]
2:mysql-community-libs-5.7.32-1.el7################################# [ 50%]
3:mysql-community-client-5.7.32-1.e################################# [ 75%]
4:mysql-community-server-5.7.32-1.e################################# [100%]

2.4安装完之后的相关文件

/usr/bin目录下,主要是mysql相关的客户端命令、管理命令

[root@box1 5.7]# ls /usr/bin/mysql*
/usr/bin/mysql /usr/bin/mysqlcheck /usr/bin/mysqldump /usr/bin/mysql_install_db /usr/bin/mysql_secure_installation /usr/bin/mysql_ssl_rsa_setup
/usr/bin/mysqladmin /usr/bin/mysql_config_editor /usr/bin/mysqldumpslow /usr/bin/mysql_plugin /usr/bin/mysqlshow /usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysqlbinlog /usr/bin/mysqld_pre_systemd /usr/bin/mysqlimport /usr/bin/mysqlpump /usr/bin/mysqlslap /usr/bin/mysql_upgrade

/usr/sbin

mysqld,mysql服务器的可执行文件

[root@box1 5.7]# ls /usr/sbin/mysql*
/usr/sbin/mysqld /usr/sbin/mysqld-debug

/usr/lib64/mysql

mysql client lib和plugin lib

[root@box1 5.7]# ls /usr/lib64/mysql/
libmysqlclient.so.20 libmysqlclient.so.20.3.19 mecab plugin

/usr/share/mysql

主要是mysql字符集和error msg相关文件

[root@box1 5.7]# ls /usr/share/mysql/
bulgarian dictionary.txt estonian greek italian mysql-log-rotate mysql_system_tables.sql polish serbian ukrainian
charsets dutch fill_help_tables.sql hungarian japanese mysql_security_commands.sql mysql_test_data_timezone.sql portuguese slovak uninstall_rewriter.sql
czech english french innodb_memcached_config.sql korean mysql_sys_schema.sql norwegian romanian spanish
danish errmsg-utf8.txt german install_rewriter.sql magic mysql_system_tables_data.sql norwegian-ny russian swedish

/etc/my.cnf

配置文件

/var/lib/mysql

mysql数据文件

[root@box1 5.7]# ls /var/lib/mysql*
/var/lib/mysql: /var/lib/mysql-files: /var/lib/mysql-keyring:

启动脚本

  • 服务启动文件 /etc/systemd/system/multi-user.target.wants/mysqld.service
  • 数据库初始化脚本 /usr/bin/mysqld_pre_systemd

3 启动mysql

使用service 启动mysql实例

[root@box1 5.7]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@box1 5.7]# ps -elf | grep mysqld
1 S mysql 12663 1 0 80 0 - 280540 poll_s 08:17 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
0 S root 12959 2276 0 80 0 - 28206 pipe_w 08:21 pts/0 00:00:00 grep --color=auto mysqld

4 登陆mysql

第一次安装后,会生产mysql root账号的默认的临时密码,可以在/var/log/mysql.log中找到。

用临时密码登陆后,需要修改密码才能进行操作

[root@box1 5.7]# grep -i pass /var/log/mysqld.log
2021-03-31T12:14:47.169374Z 1 [Note] A temporary password is generated for root@localhost: _0eaf&hyQ9Ha
2021-03-31T12:23:26.373529Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO) [root@box1 5.7]# mysql -uroot -h127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.32 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select 1;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> alter user 'root'@'localhost' identified by 'helloWorld#';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by 'helloWorld#123';
Query OK, 0 rows affected (0.00 sec) mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2021-03-31 08:27:57 |
+---------------------+
1 row in set (0.00 sec)

5 关于mysql初始化

使用service启动mysql时,初次使用mysql,会执行脚本/usr/bin/mysqld_pre_systemd进行初始化,

脚本里进行了几个重要操作

  • 往mysql.plugin里添加validate_password插件
  • 使用mysqld --initialize初始化mysql系统数据库
  • 使用mysql_ssl_rsa_setup创建ssl证书文件
# more /usr/bin/mysqld_pre_systemd
... install_validate_password_sql_file () {
local initfile
initfile="$(mktemp /var/lib/mysql-files/install-validate-password-plugin.XXXXXX.sql)"
chmod a+r "$initfile"
echo "SET @@SESSION.SQL_LOG_BIN=0;" > "$initfile"
echo "INSERT INTO mysql.plugin (name, dl) VALUES ('validate_password', 'validate_password.so');" >> $initfile
echo $initfile
} ...
# If special mysql dir is in place, skip db install
[ -d "$datadir/mysql" ] && exit 0 # Create initial db and install validate_password plugin
initfile="$(install_validate_password_sql_file)"
/usr/sbin/mysqld ${instance:+--defaults-group-suffix=@$instance} --initialize \
--datadir="$datadir" --user=mysql --init-file="$initfile"
rm -f "$initfile" # Generate certs if needed
if [ -x /usr/bin/mysql_ssl_rsa_setup -a ! -e "${datadir}/server-key.pem" ] ; then
/usr/bin/mysql_ssl_rsa_setup --datadir="$datadir" --uid=mysql >/dev/null 2>&1
fi

更多技术信息请查看云掣官网https://yunche.pro/?t=yrgw

MySQL运维实战(1.1)安装部署:使用RPM进行安装部署的更多相关文章

  1. Linux运维实战之DNS(bind)服务器的安装与配置

    转自http://sweetpotato.blog.51cto.com/533893/1598225 上次博文我们讨论了DNS的基础,本次博文我们重点来看看如何配置一台DNS服务器. [本次博文的主要 ...

  2. 转 移动云基于MySQL Galera的PXC运维实战

    ##sample 1 : mysql 监控 1.phpadmin  比较简单,适合上手 2.mysql_web python 写的, https://github.com/ycg/mysql_web/ ...

  3. 公司没有 DBA,Mysql 运维自己来

    如果你的公司有 DBA,那么我恭喜你,你可以无视 Mysql 运维.如果你的公司没有 DBA,那你就好好学两手 Mysql 基本运维操作,行走江湖,防身必备. 环境:CentOS7 版本: 一.虚拟机 ...

  4. CentOS7系统管理与运维实战

    CentOS7系统管理与运维实战 下载地址 https://pan.baidu.com/s/1KFHVI-XjGaLMrh39WuhyCw 扫码下面二维码关注公众号回复100007 获取分享码 本书目 ...

  5. 搭建稳固的MySQL运维体系

    MySQL 监控要点 MySQL 监控要点,主要涉及服务器和 MySQL 两个方向的监控告警. 在这两个监控告警方向需要重点关注监控策略.监控趋势图及报警方式. 监控策略指的是每个监控项的告警阈值,例 ...

  6. Istio 运维实战系列(3):让人头大的『无头服务』-下

    本系列文章将介绍用户从 Spring Cloud,Dubbo 等传统微服务框架迁移到 Istio 服务网格时的一些经验,以及在使用 Istio 过程中可能遇到的一些常见问题的解决方法. 失败的 Eur ...

  7. mysql运维必会的一些知识点整理

    (1)基础笔试命令考察 1.开启MySQL服务 /etc/init.d/mysqld start service mysqld start systemctl start mysqld 2.检测端口是 ...

  8. 网络运维必回的模拟器-GNS软件下载和安装

    网络运维必回的模拟器-GNS软件下载和安装 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.GNS简介 1>.什么是GNS GNS3是一款具有图形化界面可以运行在多平台( ...

  9. MySQL运维开发相关的所有工具

    http://www.ruzuojun.com/topic/592.html   Percona Toolkit 安装使用 http://cenalulu.github.io/mysql/mysql- ...

  10. mysql运维必会的一些知识点整理(转自民工哥)

    (1)基础笔试命令考察 1.开启MySQL服务 /etc/init.d/mysqld start service mysqld start systemctl start mysqld 2.检测端口是 ...

随机推荐

  1. Towards Network Anomaly Detection Using Graph Embedding笔记

    Towards Network Anomaly Detection Using Graph Embedding 目录 Towards Network Anomaly Detection Using G ...

  2. 关于初次new springboot项目

    如果是新手初学,然后做springboot项目报各种错,改来改去最终都无法出现successful字样. 请先检查,maven环境是否配好. maven环境决定你下载依赖的速度,以及能否下载成功. m ...

  3. mysql8安装踩坑记

    背景:已安装mysql5.7版本 问题一:默认的3306端口被占用 进入mysql5.7的my.ini文件,更改port为3307或者其他未被占用的端口 问题二:Install/Remove of t ...

  4. C#开源且免费的Windows桌面快速预览神器 - QuickLook

    前言 今天给大家推荐一款由C#开源且免费的Windows桌面快速预览神器:QuickLook. 工具介绍 QuickLook是一款在Windows操作系统上的实用工具,它提供了一种快速预览文件内容的方 ...

  5. Jupyter_Notebook_添加代码自动补全功能

    Jupyter Notebook 添加代码自动补全功能 安装 如果之前安装过显示目录功能的话,这一步骤可以跳过. pip install jupyter_contrib_nbextensions 配置 ...

  6. PostgreSQL学习笔记-5.基础知识:触发器、索引

    PostgreSQL 触发器是数据库的回调函数,它会在指定的数据库事件发生时自动执行/调用. 下面是关于 PostgreSQL 触发器几个比较重要的点: PostgreSQL 触发器可以在BEFORE ...

  7. Docker 安装 Redis 单机&集群总结

    前言 Redis 是一个开源的使用 ANSI C 语言编写.遵守 BSD 协议.支持网络.可基于 内存 . 分布式 .可选持久性的键值对( Key-Value )存储数据库 redis版本:redis ...

  8. .NET静态代码织入——肉夹馍(Rougamo)发布2.0

    肉夹馍(https://github.com/inversionhourglass/Rougamo)通过静态代码织入方式实现AOP的组件,其主要特点是在编译时完成AOP代码织入,相比动态代理可以减少应 ...

  9. DB22

    IBM官方网站提供了DB2 Express-C版本的软件免费下载: 下载地址 : http://www.ibm.com/developerworks/cn/downloads/im/udbexp/

  10. 老派Sql之必要,逆天,我在ef core中使用ado.net!

    Wlkr.Core.EFCore 逆天,我在ef core中使用ado.net! 老派Sql之必要 当你开发生涯中基本只用一两种数据库 当你觉得用EF的类写报表时很别扭 当你觉自己的Sql( Serv ...