MySQL运维实战(1.1)安装部署:使用RPM进行安装部署
作者:俊达
我们在生产环境部署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进行安装部署的更多相关文章
- Linux运维实战之DNS(bind)服务器的安装与配置
转自http://sweetpotato.blog.51cto.com/533893/1598225 上次博文我们讨论了DNS的基础,本次博文我们重点来看看如何配置一台DNS服务器. [本次博文的主要 ...
- 转 移动云基于MySQL Galera的PXC运维实战
##sample 1 : mysql 监控 1.phpadmin 比较简单,适合上手 2.mysql_web python 写的, https://github.com/ycg/mysql_web/ ...
- 公司没有 DBA,Mysql 运维自己来
如果你的公司有 DBA,那么我恭喜你,你可以无视 Mysql 运维.如果你的公司没有 DBA,那你就好好学两手 Mysql 基本运维操作,行走江湖,防身必备. 环境:CentOS7 版本: 一.虚拟机 ...
- CentOS7系统管理与运维实战
CentOS7系统管理与运维实战 下载地址 https://pan.baidu.com/s/1KFHVI-XjGaLMrh39WuhyCw 扫码下面二维码关注公众号回复100007 获取分享码 本书目 ...
- 搭建稳固的MySQL运维体系
MySQL 监控要点 MySQL 监控要点,主要涉及服务器和 MySQL 两个方向的监控告警. 在这两个监控告警方向需要重点关注监控策略.监控趋势图及报警方式. 监控策略指的是每个监控项的告警阈值,例 ...
- Istio 运维实战系列(3):让人头大的『无头服务』-下
本系列文章将介绍用户从 Spring Cloud,Dubbo 等传统微服务框架迁移到 Istio 服务网格时的一些经验,以及在使用 Istio 过程中可能遇到的一些常见问题的解决方法. 失败的 Eur ...
- mysql运维必会的一些知识点整理
(1)基础笔试命令考察 1.开启MySQL服务 /etc/init.d/mysqld start service mysqld start systemctl start mysqld 2.检测端口是 ...
- 网络运维必回的模拟器-GNS软件下载和安装
网络运维必回的模拟器-GNS软件下载和安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.GNS简介 1>.什么是GNS GNS3是一款具有图形化界面可以运行在多平台( ...
- MySQL运维开发相关的所有工具
http://www.ruzuojun.com/topic/592.html Percona Toolkit 安装使用 http://cenalulu.github.io/mysql/mysql- ...
- mysql运维必会的一些知识点整理(转自民工哥)
(1)基础笔试命令考察 1.开启MySQL服务 /etc/init.d/mysqld start service mysqld start systemctl start mysqld 2.检测端口是 ...
随机推荐
- Mysql中文字符串提取datetime
DATE_FORMAT无法用于提取含中文字符的时间字符串中的时间, 可以通过STR_TO_DATE来提取其中的信息, 如下: SELECT STR_TO_DATE("2018年11月05日 ...
- Springboot简单功能示例-1 实现基本WEB服务
springboot-sample 介绍 springboot简单示例 跳转到发行版 查看发行版说明 软件架构(当前发行版使用) springboot 安装教程 git clone --branch ...
- 文心一言 VS 讯飞星火 VS chatgpt (118)-- 算法导论10.3 3题
三.用go语言,在ALLOCATE-OBJECT和 FREE-OBJECT过程的实现中,为什么不需要设置或重置对象的 prev 属性呢? 文心一言: 在 Go 语言中,ALLOCATE-OBJECT ...
- Centos7安装Promethus
安装Prometheus(普罗米修斯)监控: 实验环境准备: 服务器 IP地址 Prometheus服务器 192.168.1.22 被监控服务器 192.168.1.20 grafana服务器 19 ...
- 市二模&中考游记
市二模 过于久远,记不清了.当时由于不想写游记浪费备考时间所以没写. 然后就是我现在真的记不住,算了不写了( 大概是 140+150+135.5+89+68 吧. 中考 内容以各类奇闻逸事为主( \( ...
- FreeSWITCH的moh使用笔记
操作系统 :CentOS 7.6_x64 FreeSWITCH版本 :1.10.9 之前写过FreeSWITCH安装的文章,今天整理下moh使用过程中遇到的问题及解决方案,并提供moh音频下载途径.F ...
- http1.x,http2.0,https分别介绍以及他们的区别
一.HTTP/1.x Http1.x 缺陷:线程阻塞,在同一时间,同一域名的请求有一定数量限制,超过限制数目的请求会被阻塞 http1.0 缺陷:浏览器与服务器只保持短暂的连接,浏览器的每次请求都需要 ...
- Redis项目搭建
Redis项目搭建 Redis下载 搭建redis首先需要下载Redis,可是Redis官方并没有Windows安装,好在网上从不缺大牛,Github上可以找到Redis的Windows版 下载地址: ...
- musl中strlen源码实现和分析
最近在学习<C 和指针>的第 6 章指针部分,在 6.12 章节看到了 strlen 函数的实现,联想到最近有在看 musl 的源码,于是就把 musl 中 strlen 的源码认真地分析 ...
- Java——设计模式
一.概述 设计模式是历代程序员总结出的经验 二.分类 创建型模式:简单工厂模式 工厂方法模式 单例模式:饿汉式(开发) 懒汉式(面试) 行为型模式 结构型模式 三.简单工厂模式 一个工厂中可以创建很多 ...