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> 
相关推荐
mqiqe2 小时前
Python MySQL通过Binlog 获取变更记录 恢复数据
开发语言·python·mysql
工业甲酰苯胺2 小时前
MySQL 主从复制之多线程复制
android·mysql·adb
BestandW1shEs3 小时前
谈谈Mysql的常见基础问题
数据库·mysql
重生之Java开发工程师3 小时前
MySQL中的CAST类型转换函数
数据库·sql·mysql
教练、我想打篮球3 小时前
66 mysql 的 表自增长锁
数据库·mysql
Ljw...3 小时前
表的操作(MySQL)
数据库·mysql·表的操作
哥谭居民00013 小时前
MySQL的权限管理机制--授权表
数据库
wqq_9922502773 小时前
ssm旅游推荐系统的设计与开发
数据库·旅游
难以触及的高度3 小时前
mysql中between and怎么用
数据库·mysql