作者:俊达

引言

上一篇我们使用了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. skynet的timer似乎有问题

    skynet.timeout 传进去 number 范围内的数值但是会溢出, 调查发现 skynet.timeout 调用的是 c 的方法: c.intcommand("TIMEOUT&qu ...

  2. 「codeforces - 1394C」Boboniu and String

    link. 注意到 BN-string 长成什么样根本不重要,我们把它表述为 BN-pair \((x, y)\) 即可,两个 BN-strings 相似的充要条件即两者分别映射得到的 BN-pair ...

  3. 异常:no transaction is in progress

    转载请注明出处: 在使用  @Scheduled 注解创建了一个定时任务,并通过定时任务不断向mysql写入数据,写入数据的方式是通过 jpa 的方式,在代码运行的过程中出现错误:no transac ...

  4. 基于 Python 和 Vue 的在线评测系统

    基于 Docker,真正一键部署 前后端分离,模块化编程,微服务 ACM/OI 两种比赛模式.实时/非实时评判 任意选择 丰富的可视化图表,一图胜千言 支持 Template Problem,可以添加 ...

  5. jq工具及其常用用法

    近来在工作中处理JSON处理较多,深入研究了一下jq,之前对jq的使用一直停留在JSON数据格式化的层面,实际它的能力远不止于此. 在处理JSON数据时,我们经常需要在命令行中进行过滤.查询和编辑的操 ...

  6. 记一次服务器Cuda驱动崩溃修复过程

    基本过程 今天实验室师兄在服务器运行深度学习训练时候得到报错CUDA initialization: Unexpected error from cudaGetDeviceCount()疑似Cuda与 ...

  7. 针对Jupter Kernel error的问题解决

    首先打开Anaconda Prompt 输入jupyter kernelspec list查看安装的内核和位置 到显示的的目录下面找到 kernel.josn这个文件 修改为现在的python环境路径 ...

  8. 对 List 列表中的数据按指定字段进行排序

    /** * 对列表中的数据按指定字段进行排序.要求类必须有相关的方法返回字符串.整型.日期等值以进行比较. * * @param list 集合 * @param sortName 需要排序的字段,目 ...

  9. Chromium gclient使用

    gclient 是由 Google 用 Python 开发的一套跨平台的git仓库管理工具,它的作用类似 git 的 submodule,用来将多个git仓库组成一个solution进行管理,比如ch ...

  10. OceanBase金融SQL、亿万级别据量优化案例(Row_number 开窗 + 分页SQL)

    最近优化了不少SQL,简单的SQL顺手搞了不好意思发出来了忽悠人,复杂很考验逻辑思维的,但是又不想分享出来(自己收藏的案例),怕被人抄袭思路. 今天遇到一条很有意思的SQL案例:  性能SQL(金融行 ...