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> 
相关推荐
xixixi7777713 分钟前
进一步了解一下现代数字经济的核心动脉——DCI(数据中心互联 )
网络·数据库·安全·光通信·数据·通信·dci
222you20 分钟前
在云服务器上配置redis环境(OpenCloudOS)
数据库·redis·缓存
智能化咨询21 分钟前
(99页PPT)智慧景区一体化建设方案(附下载方式)
大数据·数据库
AI题库22 分钟前
PostgreSQL 18 从新手到大师:实战指南 - 1.2 关系型数据库基础
数据库·postgresql
IT教程资源D1 小时前
[N_101]基于springboot,vue企业网盘系统
mysql·vue·前后端分离·springboot网盘
我可以将你更新哟1 小时前
【爬虫】爬取斗罗大陆漫画,面向对象封装(存入数据库)
数据库·爬虫·python
忙里偷闲学python1 小时前
mysql
linux·数据库·mysql·oracle
byzh_rc1 小时前
[算法设计与分析-从入门到入土] 递归
数据库·人工智能·算法·机器学习·支持向量机
学Linux的语莫1 小时前
Milvus向量数据库的基础连接操作
数据库·milvus
小智RE0-走在路上1 小时前
Python学习笔记(13) --Mysql,Python关联数据库
数据库·python·学习