官网

根据自己的系统版本挑选不同的MySQL版本
https://dev.mysql.com/downloads/mysql/

Mysql

红帽系列部署过程

系统环境
        #####           root@alma-server 
       #######          ---------------- 
       ##O#O##          OS: AlmaLinux 9.3 (Shamrock Pampas Cat) x86_64 
       #######          Host: VMware20,1 None 
     ###########        Kernel: 5.14.0-362.8.1.el9_3.x86_64 
    #############       Uptime: 22 mins 
   ###############      Packages: 909 (rpm) 
   ################     Shell: bash 5.1.8 
  #################     Resolution: 1280x800 
#####################   Terminal: /dev/pts/1 
#####################   CPU: 11th Gen Intel i5-11400F (4) @ 2.592GHz 
  #################     GPU: 00:0f.0 VMware SVGA II Adapter 
                        Memory: 777MiB / 7641MiB 

                                              
安装依赖
dnf install -y perl libtirpc net-tools wget tar tree
MySQL安装包下载

我这里选择的是Red Hat Enterprise Linux / Oracle Linux MySQL 8.4.0 LTS MySQL Community Server 8.4.0 LTS

wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.0-1.el9.x86_64.rpm-bundle.tar
解压MySQL安装包压缩文件
tar -xvf mysql-8.4.0-1.el9.x86_64.rpm-bundle.tar
安装顺序
  • [ ] 1.mysql-community-common
  • [ ] 2.mysql-community-client-plugins
  • [ ] 3.mysql-community-libs
  • [ ] 4.mysql-community-icu-data-files
  • [ ] 5.mysql-community-client
  • [ ] 6.mysql-community-server
rpm -ivh mysql-community-common-8.4.0-1.el9.x86_64.rpm &&\
rpm -ivh mysql-community-client-plugins-8.4.0-1.el9.x86_64.rpm &&\
rpm -ivh mysql-community-libs-8.4.0-1.el9.x86_64.rpm &&\
rpm -ivh mysql-community-icu-data-files-8.4.0-1.el9.x86_64.rpm &&\
rpm -ivh mysql-community-client-8.4.0-1.el9.x86_64.rpm &&\
rpm -ivh mysql-community-server-8.4.0-1.el9.x86_64.rpm
检查

通过命令检查是否安装

mysqladmin --version

mysqladmin Ver 8.4.0 for Linux on x86_64 (MySQL Community Server - GPL)

MySQL 初始化
mysqld --initialize --console
设置MySQL用户权限
chown -R mysql:mysql /var/lib/mysql
通过日志文件查看root账户临时密码
grep "password is generated" /var/log/mysqld.log | awk '{print $NF}'
启动MySQL服务组件
systemctl enable mysqld && systemctl start mysqld
更改ROOT账户密码
mysql -uroot -p'临时密码'

进入MySQL 更改ROOT账户密码

#xxxx表示输入的新密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'xxx';
flush privileges;
允许ROOT账户远程访问
use mysql;
update user set host ='%' where user = 'root';
flush privileges;
ERROR 1227 (42000)**
Mysql8 提示:ERROR 1227 (42000): Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
原因:MySQL 8 版本中新增了一个system_user帐户类型,由于root用户没有SYSTEM_USER权限,导致错误出现。

为root添加权限:

grant system_user on . to ‘root’;
flush privileges;
新增管理员用户

MySQL 8数据库中创建一个用户,并为该用户授予可以登录MySQL的权限。打开MySQL 8,在终端输入以下代码创建一个新用户

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

其中,’newuser’是你要创建的用户名,’localhost’代表该用户只能在本地登录, ‘password’是该用户要登录的密码。接着授予该用户登录MySQL的权限

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

防火墙开放端口号流程

1. 添加需要开放的端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent
#permanent代表永久添加 

2. 重启防火墙

firewall-cmd --reload

3. 查看防火墙端口是否开放

 firewall-cmd --list-ports

乌班图系列部署过程

安装依赖

apt install libmecab2 libaio1t64 tar wget curl -y

下载安装包

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-server_8.0.38-1ubuntu24.04_amd64.deb-bundle.tar

解压安装

tar -xvf mysql-server_8.0.38-1ubuntu24.04_amd64.deb-bundle.tar

dpkg -i mysql-community-client-plugins_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-community-client-core_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-common_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-community-client_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i libmysqlclient21_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i libmysqlclient-dev_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-client_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-community-server-core_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-community-server_8.0.38-1ubuntu24.04_amd64.deb
dpkg -i mysql-server_8.0.38-1ubuntu24.04_amd64.deb

启动服务

mysqladmin --version && systemctl start mysql
systemctl daemon-reload
systemctl enable mysql && systemctl start mysql
最后修改:2024 年 07 月 19 日
如果觉得我的文章对你有用,请随意赞赏