linux 安装mysql

前言:

  • MySQL Community Server社区版本,开源免费,自由下载但是不提供官方技术支持。

  • MySQL Enterprise Edition 企业版本,需付费,不能在线下载,可以试用30天。提供了更多的功能和更完备的技术支持,更适合于对数据库的功能和可靠性要求较高的企业客户。

  • MySQL Cluster集群版,开源免费。用于架设集群服务器,可将几个MySQL Server封装成一个Server。需要在社区版或企业版的基础上使用。

  • MySQL Cluster CGE高级集群版,需付费。

rmp 安装流程

操作系统:CentOS7
MySQL Community:8.0
下载地址:https://dev.mysql.com/downloads/mysql/

1、卸载MariaDB

安装MySQL的话会和MariaDB的文件冲突,需要先卸载掉MariaDB。

rpm -qa|grep mariadb  # 查看 mariadb安装文件

rpm -e --nodeps 文件名  # 卸载 mariadb, 或 yum remove mysql-libs

rpm -qa|grep mariadb  # 确认是否卸载干净

2、安装依赖

yum -y install libaio numactl

3、下载mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar

# 建议进入个人准备的目录,下载 软件包:cd /opt/software/mysql

[root@localhost mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar

4、解压tar包

[root@localhost mysql]# tar -xf mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar

5、rpm安装

[root@localhost mysql]# rpm -ivh mysql-community-common-8.0.37-1.el7.x86_64.rpm

[root@localhost mysql]# rpm -ivh mysql-community-client-plugins-8.0.37-1.el7.x86_64.rpm

[root@localhost mysql]# rpm -ivh mysql-community-libs-8.0.37-1.el7.x86_64.rpm

[root@localhost mysql]# rpm -ivh mysql-community-client-8.0.37-1.el7.x86_64.rpm

[root@localhost mysql]# rpm -ivh mysql-community-icu-data-files-8.0.37-1.el7.x86_64.rpm

[root@localhost mysql]# rpm -ivh mysql-community-server-8.0.37-1.el7.x86_64.rpm

注:注意 rpm 文件的安装顺序,不然可能会报错。如果报错也不要紧,错误信息中会有提示需要提前安装的 依赖文件。

6、确认rpm包是否安装成功

[root@localhost mysql]# rpm -qa|grep -i mysql
mysql-community-libs-8.0.37-1.el7.x86_64
mysql-community-client-8.0.37-1.el7.x86_64
mysql-community-server-8.0.37-1.el7.x86_64
mysql-community-common-8.0.37-1.el7.x86_64
mysql-community-client-plugins-8.0.37-1.el7.x86_64
mysql-community-icu-data-files-8.0.37-1.el7.x86_64

7、查看mysql版本(确认mysql安装完成)

[root@localhost mysql]# mysql --version
mysql  Ver 8.0.37 for Linux on x86_64 (MySQL Community Server - GPL)

8、查看并启动mysql服务

[root@localhost mysql]# systemctl status mysqld
[root@localhost mysql]# systemctl start mysqld

9、服务的初始化

[root@localhost mysql]# mysqld --initialize --user=mysql

说明:--initialize 选项默认是以“安全”模式来初始化,则会为root用户生成一个密码并将该密码标记为过期,登录后需要设置一个新的密码。生成的临时密码会往日志中记录一份。

10、查看生成的临时密码

[root@localhost mysql]# cat /var/log/mysqld.log
2024-08-26T09:37:52.026359Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.37) initializing of server in progress as process 123087
2024-08-26T09:37:52.036793Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-08-26T09:37:52.288583Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-08-26T09:37:53.068852Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3Hpq+s%upzt?
2024-08-26T09:37:55.431142Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.37) starting as process 123129

注:A temporary password is generated for root@localhost: 3Hpq+s%upzt? 显示的临时密码为:3Hpq+s%upzt?

11、进入mysql控制台:

[root@localhost mysql]# mysql -h localhost -u root -P 3306 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.37

12、修改root密码:

mysql> ALTER USER USER() IDENTIFIED BY 'Test_1024';   -- 一定要先改 USER() 密码,USER()其实就是root
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password.policy = LOW;  -- 更改密码策略:"LOW" 低复杂
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password.length = 6;  -- 更改密码长度策略:6位密码
Query OK, 0 rows affected (0.00 sec)

mysql> quit  -- 退出

13、设置服务自启动

systemctl list-unit-files|grep mysqld.service   # 查看是否开启 开机自启动

systemctl enable mysqld.service  # 开启 开机自启动服务

systemctl disable mysqld.service  # 关闭 开机自启动服务

完成!!!

参考文档:

posted @ 2024-08-26 16:57  二月雪  阅读(46)  评论(0编辑  收藏  举报