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> 
相关推荐
零炻大礼包26 分钟前
【SQL server】数据库远程连接配置
数据库
zmgst35 分钟前
canal1.1.7使用canal-adapter进行mysql同步数据
java·数据库·mysql
令狐少侠201135 分钟前
explain执行计划分析 ref_
mysql
随心............36 分钟前
python操作MySQL以及SQL综合案例
数据库·mysql
€☞扫地僧☜€37 分钟前
docker 拉取MySQL8.0镜像以及安装
运维·数据库·docker·容器
CopyDragon42 分钟前
设置域名跨越访问
数据库·sqlite
xjjeffery43 分钟前
MySQL 基础
数据库·mysql
写bug的小屁孩1 小时前
前后端交互接口(三)
运维·服务器·数据库·windows·用户界面·qt6.3
恒辉信达1 小时前
hhdb数据库介绍(8-4)
服务器·数据库·mysql
齐 飞2 小时前
MongoDB笔记01-概念与安装
前端·数据库·笔记·后端·mongodb