作者:俊达

引言

上一篇我们使用了RPM进行安装部署,这是一种安装快速、简化部署和管理过程、与操作系统提供的包管理工具紧密集成的部署方法。此外,当你需要更高的灵活性和自定义性,并且愿意承担一些额外的手动配置和管理工作,那么二进制安装是一个值得考虑选择。

以下是二进制安装的一些优势:

  • 处理单机多实例:在某些情况下,希望在一台计算机上开启多个不同的服务器 ,运行多个MySQL服务进程,同时保持现有的生产设置不受干扰。使用二进制方式可以在单台机器上部署多个实例,无需额外的配置。
  • 简化升级过程:在生产环境中,MySQL的升级是一个重要且敏感的操作。使用二进制安装,原地升级的方式更加方便。只需关闭旧的 MySQL 服务器、用新的替换旧的 MySQL 二进制文件或软件包、在现有数据目录上重新启动 MySQL,以及升级现有安装中需要升级的任何剩余部分即可。
  • 自定义编译:有时候,可能需要对MySQL进行一些特定的定制或打补丁,以满足特定的业务需求。通过自己编译二进制文件,可以灵活地添加或修改功能,并满足特殊需求。这种自定义编译的方式可以让MySQL更好地适应不同的环境和需求。

1 下载二进制文件

根据操作系统版本,下载二进制包



下载其中的Compressed TAR,如:

2 解压

将下载的二进制文件下载到某个目录。

一般我们会将mysql二进制文件放到/usr/local/mysql 或者 /opt/mysql。

tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz -C /opt
mv mysql-8.0.32-linux-glibc2.12-x86_64 mysql
ls /opt/mysql/
bin docs include lib LICENSE man README share support-files

3 准备配置文件

我们规划将MySQL数据库文件放在/data/mysql01路径下。

mysql数据目录: /data/mysql01/

配置文件:/data/mysql01/my.cnf

[mysqld]
#dir
basedir=/opt/mysql
lc_messages_dir=/opt/mysql/share datadir=/data/mysql01/data
tmpdir=/data/mysql01/tmp
log-error=/data/mysql01/log/alert.log
slow_query_log_file=/data/mysql01/log/slow.log
general_log_file=/data/mysql01/log/general.log socket=/data/mysql01/run/mysql.sock #innodb
innodb_data_home_dir=/data/mysql01/data
innodb_log_group_home_dir=/data/mysql01/data
innodb_data_file_path=ibdata1:128M:autoextend

配置文件核心内容是[mysqld]下的相关路径配置:

basedir: mysql二进制文件路径

datadir: mysql数据目录

这里只配置了启动MySQL需要的最基本的参数。

真实环境中,需要根据业务需求和服务器配置优化配置,后续单独讲。

4 初始化数据库

-- 创建mysql用户
groupadd mysql
useradd mysql -g mysql -- 创建相关目录
mkdir -p /data/mysql01/{data,binlog,log,run,tmp}
chown -R mysql:mysql /data/mysql01 -- 初始化数据库
./bin/mysqld --defaults-file=/data/mysql01/my.cnf --initialize --user=mysql

初始化完成后,查看alert.log中的临时密码

tail /data/mysql01/log/alert.log

2021-03-29T11:20:45.693865Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-03-29T11:20:45.789596Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-03-29T11:20:45.865865Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ce7101f3-9080-11eb-9d26-080027475f71.
2021-03-29T11:20:45.869311Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-03-29T11:20:46.234753Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-29T11:20:46.286920Z 1 [Note] A temporary password is generated for root@localhost: kguRrCbXw9;

5 启动实例

mysql服务器进程是mysqld, 可以通过执行mysqld命令直接启动数据库,当然通常我们会使用一些封装过的脚本来启动mysql。

mysqld_safe就是一个常用的脚本,它能启动mysqld,并在mysqld异常退出后重新启动mysqld

[root@box1 ~]# ./bin/mysqld_safe --defaults-file=/data/mysql01/my.cnf &
[1] 27896 [root@box1 ~]# 2021-03-29T11:24:31.202499Z mysqld_safe Logging to '/data/mysql01/log/alert.log'.

通过ps,可以看到mysqld进程,以及命令行参数,mysqld_safe是mysqld的父进程。

[root@box1 mysql]# ps -elf | grep mysqld
4 S root 6445 2276 0 80 0 - 28354 do_wai 05:20 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql01/my.cnf
4 S mysql 6738 6445 0 80 0 - 518211 poll_s 05:20 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql01/my.cnf --basedir=/usr/local --datadir=/data/mysql01/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql01/log/alert.log --pid-file=box1.pid --socket=/data/mysql01/run/mysql.sock
0 S root 6784 2276 0 80 0 - 28206 pipe_w 05:21 pts/0 00:00:00 grep --color=auto mysqld

可以看到mysqld命令行的关键参数

--defaults-file: 启动参数文件

--basedir: mysql软件的basedir

--datadir: 数据目录

--plugin-dir: mysql插件lib库路径

--user: 运行mysql的OS账号

--log-error: 错误日志路径

--socket: socket连接文件

如果不提供这些参数,mysqld会使用编译时的默认参数。

默认参数:

[root@box1 mysql]# ./bin/mysqld  --print-defaults
./bin/mysqld would have been started with the following arguments:
--datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --symbolic-links=0

默认参数文件路径:

[root@box1 mysql]# ./bin/mysqld  --verbose --help | more
2021-03-31T09:33:30.820738Z 0 [ERROR] COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8mb4'
./bin/mysqld Ver 5.7.32-debug for Linux on x86_64 (lazybug)
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. Starts the MySQL database server. Usage: ./bin/mysqld [OPTIONS] Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.7
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file,
except for login file.
--defaults-file=# Only read default options from the given file #.

通过mysqld --verbose --help可以看到参数文件搜索路径:

/etc/my.cnf, /etc/mysql/my.cnf, /usr/local/mysql/etc/my.cnf, ~/.my.cnf

在运维多实例mysql时,我们通常会指定my.cnf的路径,而不使用默认路径的配置文件。

避免读取默认配置参数文件中的配置,引起各种问题。

加了--defaults-file后,就只会从defaults-file指定文件中读取配置。

日志文件

如果启动过程中有问题,可以通过alert日志文件查看具体的问题

$ tail -100 /data/mysql01/log/alert.log

2021-03-29T11:24:31.229330Z mysqld_safe Starting mysqld daemon with databases from /data/mysql01/data
2021-03-29T11:24:31.407665Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.32-debug) starting as process 28189 ...
2021-03-29T11:24:31.412908Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-03-29T11:24:31.412934Z 0 [Note] InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
2021-03-29T11:24:31.412939Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-03-29T11:24:31.412942Z 0 [Note] InnoDB: Uses event mutexes
2021-03-29T11:24:31.412947Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-03-29T11:24:31.412950Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-03-29T11:24:31.412954Z 0 [Note] InnoDB: Using Linux native AIO
2021-03-29T11:24:31.413276Z 0 [Note] InnoDB: Number of pools: 1
2021-03-29T11:24:31.413391Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-03-29T11:24:31.414823Z 0 [Note] InnoDB: Initializing buffer pool, total size = 512M, instances = 1, chunk size = 128M
2021-03-29T11:24:31.589281Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-03-29T11:24:31.594759Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-03-29T11:24:31.611389Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-03-29T11:24:31.667674Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-03-29T11:24:31.667861Z 0 [Note] InnoDB: Setting file '/data/mysql01/data/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-03-29T11:24:31.680116Z 0 [Note] InnoDB: File '/data/mysql01/data/ibtmp1' size is now 12 MB.
2021-03-29T11:24:31.685528Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-03-29T11:24:31.685540Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-03-29T11:24:31.689004Z 0 [Note] InnoDB: Waiting for purge to start
2021-03-29T11:24:31.741474Z 0 [Note] InnoDB: 5.7.32 started; log sequence number 2746702
2021-03-29T11:24:31.742643Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql01/data/ib_buffer_pool
2021-03-29T11:24:31.742725Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-03-29T11:24:31.752433Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210329 7:24:31
2021-03-29T11:24:31.757409Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-03-29T11:24:31.757426Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-03-29T11:24:31.758133Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-29T11:24:31.758185Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-03-29T11:24:31.758504Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2021-03-29T11:24:31.759379Z 0 [Note] IPv6 is available.
2021-03-29T11:24:31.759408Z 0 [Note] - '::' resolves to '::';
2021-03-29T11:24:31.759434Z 0 [Note] Server socket created on IP: '::'.
2021-03-29T11:24:31.796451Z 0 [Note] Event Scheduler: Loaded 0 events
2021-03-29T11:24:31.796935Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.7.32-debug' socket: '/data/mysql01/run/mysql.sock' port: 3306 lazybug

日志文件最后一行显示启动成功,提示本地socket文件路径和监听端口。

6 修改默认密码

mysql 5.7开始,需要先修改密码,才能正常访问数据库:

[root@box1 run]# /usr/local/mysql/bin/mysql -uroot -h127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.32-debug 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';
Query OK, 0 rows affected (0.00 sec) mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

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

MySQL运维实战(1.2)安装部署:使用二进制安装部署的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. 《Splunk智能运维实战》——1.7 为本书加载样本数据

    本节书摘来自华章计算机<Splunk智能运维实战>一书中的第1章,第1.7节,作者 [美]乔史·戴昆(Josh Diakun),保罗R.约翰逊(Paul R. Johnson),德莱克·默 ...

  10. Istio 运维实战系列(2):让人头大的『无头服务』-上

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

随机推荐

  1. Django-rest-framework框架——路由组件、认证权限频率

    @ 目录 一 路由Routers 1.1 使用方法 1.2 代码演示 1.2 视图集中附加action的声明 1.3 路由router形成URL的方式 认证权限频率 一 认证Authenticatio ...

  2. 前端三件套系例之HTML——HTML5基础

    1.HTML 1-1 什么是HTML HTML是用来制作网页的标记语言 HTML是Hypertext Markup Language的英文缩写,即超文本标记语言 HTML语言是一种标记语言,不需要编译 ...

  3. Python学习 —— 初步认知

    写在前面 Python是一种流行的高级编程语言,具有简单易学.代码可读性高.应用广泛等优势.它是一种解释型语言,可以直接在终端或集成开发环境(IDE)中运行,而无需事先编译. Python的安装 Py ...

  4. FFmpeg FFmpeg

     FFmpeg About News Download Documentation Community Code of Conduct Mailing Lists IRC Forums Bug Rep ...

  5. MySQL快速导入千万条数据(2)

    目录 一.导入前1000万条数据 二.导入前2000万条数据 三.导入后面的1000万条数据 四.建索引 五.总结 接上文,继续测试3000万条记录快速导入数据库. 一.导入前1000万条数据 清库. ...

  6. 【RocketMQ】RocketMQ存储结构设计

    CommitLog 生产者向Broker发送的消息,会以顺序写的方式,写入CommitLog文件,CommitLog文件的根目录由配置参数storePathRootDir决定,默认每一个CommitL ...

  7. APP攻防--反模拟器&反代理&反证书&真机逃逸&XP框架&Frida技术

    APP攻防--反模拟器&反代理&反证书&真机逃逸&XP框架&Frida技术 APP抓包技术 关于APP抓包,使用burpsuite抓模拟器中的数据包,需要将模拟 ...

  8. 从零实现的浏览器Web脚本

    从零实现的浏览器Web脚本 在之前我们介绍了从零实现Chrome扩展,而实际上浏览器级别的扩展整体架构非常复杂,尽管当前有统一规范但不同浏览器的具体实现不尽相同,并且成为开发者并上架Chrome应用商 ...

  9. 解决报错Invalid bound statement (not found)

    解决报错Invalid bound statement (not found) 问题描述: 在玩mybatis-plus的时候,在测试类写了一个测试批量插入的方法,结果就报错: 它的意思是 无效的跳转 ...

  10. 7z 一键压缩备份

    该批处理已开源 开原地址: 点击进入 磁盘备份 工具有很多,如果你需要增量式备份的话,以下这些方法并不适合你.goodsync 可以了解一下. 以下方式仅适用于,懒人一键压缩备份. 对于我来说 定期的 ...