简单安装mysql5.7版本

本文详细介绍了如何在Linux系统中安装MySQL5.7版本,包括下载软件包、传输、解压、修改环境变量、创建用户、初始化数据、编辑配置文件及启动数据库等步骤,并提到了两种初始化数据的方法和新版本的密码安全机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载MySQL5.7版本软件包

从官网或清华源或阿里源进行下载
在这里插入图片描述

2.将压缩包传输到xshell里

使用命令:rz -y
在这里插入图片描述

3.创建目录并将压缩包上传到此目录

[root@mysql01 ~]# mkdir /app
[root@mysql01 ~]# mv mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz /app/
[root@mysql01 ~]# 

在这里插入图片描述

4.进行解压并改名为mysql

[root@mysql01 app]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@mysql01 app]# ll
total 367716
drwxr-xr-x 9 7161 31415       129 Jun  2  2020 mysql-5.7.31-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root  376537503 Mar  2 14:32 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@mysql01 app]# mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
[root@mysql01 app]# ll
total 367716
drwxr-xr-x 9 7161 31415       129 Jun  2  2020 mysql
-rw-r--r-- 1 root root  376537503 Mar  2 14:32 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@mysql01 app]# 

在这里插入图片描述

5.修改环境变量

vim /etc/profile
在最后一行添加:export PATH=/app/mysql/bin:$PATH
然后退出进行:source /etc/profile

6.创建mysql用户

[root@mysql01 app]# useradd mysql
[root@mysql01 app]# 

在这里插入图片描述

7.创建数据目录并修改权限

[root@mysql01 app]# mkdir -p /data/mysql
[root@mysql01 app]# chown -R mysql.mysql /app/mysql/*
[root@mysql01 app]# chown -R mysql.mysql /data/mysql

在这里插入图片描述

8.进行初始化数据两种方法:

方法一:管理员会有一个临时密码

初始化数据,初始化管理员的临时密码
mysqld --initialize  --user=mysql --basedir=/app/mysql --datadir=/data/mysql

2019-04-18T03:21:53.381108Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-18T03:21:54.583415Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-18T03:21:54.697859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-18T03:21:54.760821Z 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: 1daa0c57-6189-11e9-bc80-000c294234c8.
2019-04-18T03:21:54.770856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-18T03:21:54.772016Z 1 [Note] A temporary password is generated for root@localhost: 9LN.fh_Ea#uU

在这里插入图片描述

上面报错原因: Linux系统中缺少libaio-devel 软件包
解决:

yum install -y libaio-devel

在这里插入图片描述

报错原因:
在/data/mysql 已经存在文件 进行删除即可
解决:

\rm -rf /data/mysql/*

方法二:初始化管理员没有临时密码

[root@mysql01 app]# mysqld --initialize-insecure  --user=mysql --basedir=/app/mysql --datadir=/data/mysql




2021-04-06T12:22:05.306577Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-06T12:22:05.507922Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-04-06T12:22:05.548212Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-04-06T12:22:05.606748Z 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: b30ae8bc-96d2-11eb-a8f7-000c29f96843.
2021-04-06T12:22:05.607895Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-04-06T12:22:06.748277Z 0 [Warning] CA certificate ca.pem is self signed.
2021-04-06T12:22:07.066544Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@mysql01 app]# 

版本新特性重要说明:

5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合
3.密码过期时间为180天

9.编辑默认配置文件

[root@mysql01 app]# vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=mysql [\\d]>

在这里插入图片描述

10.启动mysql

[root@mysql01 ~]# /app/mysql/support-files/mysql.server start

Starting MySQL.Logging to '/data/mysql/mysql01.err'.
 SUCCESS! 
[root@mysql01 ~]# 

在这里插入图片描述

11.启动命令太长可以用/etc/init.d/进行启动

[root@mysql01 ~]# cd /app/mysql/support-files/
[root@mysql01 support-files]# cp mysql.server /etc/init.d/mysqld 
[root@mysql01 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@mysql01 ~]# 

12.使用systemd管理数据库

[root@mysql01 ~]# vim /etc/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

在这里插入图片描述

注意:将原来模式启动mysqld先关闭,然后再用systemd管理。

[root@mysql01 ~]# systemctl start mysqld.service 
[root@mysql01 ~]# 

在这里插入图片描述

13.登陆数据库即可

ps:如果使用方法一进行初始化数据 , 那么登陆mysql需要加上管理员用户名和临时密码进行登陆。
ps:如果使用方法二进行初始化数据 , 那么直接输入mysql进行登陆即可, 不需要加管理员用户和密码进行登陆。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值