MySQL的二进制安装

MySQL的安装方式除了常规的源码编译安装外,最常用的还包括YUM方式安装和二进制方式安装。二进制安装方式中,包括rpm版本以及glibc版本。rpm版本就是在特定Linux版本下编译的,如果你的Linux版本不匹配,就可以安装。如下载CentOS7系统所对应编译好的rpm包安装即可。另外一种二进制安装包是基于特定glibc版本编译的,这里主要讲解基于glibc方式安装MySQL。

1. 基础环境准备

如果采用CentOS 7 minimal系统的安装,在使用前需要安装一些基础软件包工具

复制代码
[root@node2 ~]# yum -y install gcc vim wget net-tools lrzsz

安装MySQL依赖的软件包

复制代码
[root@node2 ~]# yum -y install libaio

创建运行MySQL程序的用户

复制代码
[root@node2 ~]# useradd -M -s /sbin/nologin mysql

关闭selinux和防火墙

复制代码
[root@node2 ~]# getenforce 
Disabled
[root@node2 ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@node2 ~]# 

2. 二进制安装

二进制安装的版本采用跟上面编译安装的版本一样MySQL 5.7.28。首先需要下载该软件包或提前上传,然后再解压进行配置

复制代码
[root@node2 ~]# tar zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz  //解包
[root@node2 ~]# mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql  //移动到/usr/local目录下并进行重命名
[root@node2 ~]# mkdir /usr/local/mysql/data   //创建文件夹
[root@node2 ~]# chown -R mysql.mysql /usr/local/mysql/data/    //更改宿主和宿主目录
[root@node2 ~]# cd /usr/local/mysql/bin/
[root@node2 bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2024-03-02T06:13:59.194153Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-03-02T06:13:59.491263Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-03-02T06:13:59.555504Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-03-02T06:13:59.613151Z 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: 0f0c7bc6-d85c-11ee-9791-000c29f2ca28.
2024-03-02T06:13:59.614551Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-03-02T06:14:00.334898Z 0 [Warning] CA certificate ca.pem is self signed.
2024-03-02T06:14:00.655548Z 1 [Note] A temporary password is generated for root@localhost: yQ4K(--Zhq(2

3. 设定配置文件

MySQL的配置文件跟上面编译安装的配置文件类似

复制代码
[root@node2 ~]# vim /etc/my.cnf

[mysqld]
[client]
socket=/usr/local/mysql/data/mysql.sock

[mysqld]
socket=/usr/local/mysql/data/mysql.sock
bind-address = 0.0.0.0
port = 3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=2048
character-set-server=utf8
default-storage-engine=INNODB

将MySQL的可执行文件写入环境变量中

复制代码
[root@node2 ~]# echo "export PATH=$PATH:/usr/local/myql/bin" >> /etc/profile
[root@node2 ~]# . /etc/profile

4. 配置systemctl方式启动

将MySQL添加成为系统服务,通过使用systemctl来管理。在/usr/local/mysql/support-files目录下找到mysql.server文件,将其复制到/etc/rc.d/init.d目录下,改名为mysqld并赋予可执行权限

复制代码
[root@node2 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@node2 ~]# chmod +x /etc/rc.d/init.d/mysqld

编辑生成mysql.service服务,通过systemctl方式来管理

复制代码
[root@node2 ~]# vim /lib/systemd/system/mysqld.service 

[Unit]
Description=mysqld
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/mysqld start
ExecReload=/etc/rc.d/init.d/mysqld reload
ExecStop=/etc/rc.d/init.d/mysqld stop

[Install]
WantedBy=multi-user.target
[root@node2 ~]# systemctl daemon-reload         //重载服务
[root@node2 ~]# systemctl enable mysqld
[root@node2 ~]# systemctl start mysqld
[root@node2 ~]# netstat -anpt | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      9310/mysqld         
[root@node2 ~]#

最后再进行修改root密码即可

复制代码
[root@node2 ~]# mysql -u root -p
Enter password:         //输入上面随机的root密码,然后修改密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28

Copyright (c) 2000, 2019, 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> set password = password('ABCabc-123');        //单引号内为新密码
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> 
相关推荐
foolishlee2 分钟前
Neon wal日志处理流程
数据库
星马梦缘10 分钟前
数据库 事务管理 专项作战记录
数据库
名字还没想好☜25 分钟前
Python concurrent.futures 实战:用 ThreadPoolExecutor 并发处理 + as_completed 收结果
数据库·python·php·并发
空杆推不起38 分钟前
穿透数据库 JOIN 核心:语法分类、底层算法、生产优化与高频坑点全解析
数据库·oracle
xxwl5851 小时前
数据库后端接口测试报告
spring boot·mysql·tomcat
xqqxqxxq1 小时前
MySQL 数据类型笔记
数据库·笔记·mysql
Logintern092 小时前
理解MySQL数据库的“事务与锁”
数据库·mysql
朱容zr3331332 小时前
为什么推荐使用自增主键?使用UUID作为主键的优缺点是什么?
java·运维·数据库·后端·mysql·面试·性能优化
麻瓜code2 小时前
【Redis 】数据类型、持久化与过期删除
数据库·redis·缓存
空杆推不起2 小时前
穿透 Flink CDC 表层用法:数据库日志捕获机制、Flink Source 运行时、端到端一致性底层原理详解
大数据·数据库·flink