在linux上安装mysql,最全的安装过程

安装linux系统下的mysql

1.查看是否安装了mysql;

rpm -qa |grep mysql #如果没有输出任何东西,证明没有安装

2.找到liunx的版本,下载对应版本的mysql。

cat /ect/redhat - release

3.下载适合版本的文件来源。

#获取我们的文件,通过在linux系统里输入命令和地址
wget https://dev.mysql.com/get/mysql75-community-release-el8-1.noarch.rpm
#通过找到mysql的官网,在官网上进行下载。
https://www.mysql.com/
选择:downloads
选择:MySQL Community (GPL) Downloads »
选择:MySQL Yum Repository
选择:合适的版本。
选择:No thanks, just start my download.
下载成功后,使用ftp,将文件上传至linux系统中的固定目录。

4.安装mysql源文件:

rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

显示内容:

警告:mysql80-community-release-el7-3.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql80-community-release-el7-3  ################################# [100%]

5.源文件是否安装成功:

cd /etc/yum.repos.d

显示两个文件:

mysql-community.repo  mysql-community-source.repo

6.查看mysql的相关资源:

yum repolist enabled |grep "mysql.*-community.*"

显示:

mysql-connectors-community/x86_64       MySQL Connectors Community           154
mysql-tools-community/x86_64            MySQL Tools Community                 75
mysql80-community/x86_64                MySQL 8.0 Community Server           189

7.选择mysql的版本:

切换mysql的版本

yum-config-manager --disable mysql80-community #关闭80版本

yum-config-manager --enable mysql5.7-community #打开5.7版本

8.安装mysql

yum install mysql-community-server.x86_64 

结果:

已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
mysql-connectors-community                                                                                                                                                                                                                             | 2.6 kB  00:00:00     
Not using downloaded mysql-connectors-community/repomd.xml because it is older than what we have:
  Current   : Mon Oct 18 15:32:33 2021
  Downloaded: Mon Oct 18 15:32:28 2021
mysql-tools-community                                                                                                                                                                                                                                  | 2.6 kB  00:00:00     
Not using downloaded mysql-tools-community/repomd.xml because it is older than what we have:
  Current   : Fri Oct 15 19:06:34 2021
  Downloaded: Fri Oct 15 19:06:19 2021
mysql57-community                                                                                                                                                                                                                                      | 2.6 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.36-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.36-1.el7,它被软件包 mysql-community-server-5.7.36-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.36-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.36-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.36-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.7.36-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要
---> 软件包 mysql-community-libs.x86_64.0.5.7.36-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.36-1.el7 将被 舍弃
---> 软件包 postfix.x86_64.2.2.10.1-7.el7 将被 升级
---> 软件包 postfix.x86_64.2.2.10.1-9.el7 将被 更新
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================================================================================================================================================
 Package                                                                     架构                                                   版本                                                              源                                                                 大小
==============================================================================================================================================================================================================================================================================
正在安装:
 mysql-community-libs                                                        x86_64                                                 5.7.36-1.el7                                                      mysql57-community                                                 2.4 M
      替换  mariadb-libs.x86_64 1:5.5.60-1.el7_5
 mysql-community-libs-compat                                                 x86_64                                                 5.7.36-1.el7                                                      mysql57-community                                                 1.2 M
      替换  mariadb-libs.x86_64 1:5.5.60-1.el7_5
 mysql-community-server                                                      x86_64                                                 5.7.36-1.el7                                                      mysql57-community                                                 174 M
为依赖而安装:
 mysql-community-client                                                      x86_64                                                 5.7.36-1.el7                                                      mysql57-community                                                  25 M
 mysql-community-common                                                      x86_64                                                 5.7.36-1.el7                                                      mysql57-community                                                 310 k
为依赖而更新:
 postfix                                                                     x86_64                                                 2:2.10.1-9.el7                                                    base                                                              2.4 M

事务概要
==============================================================================================================================================================================================================================================================================
安装  3 软件包 (+2 依赖软件包)
升级           ( 1 依赖软件包)

总计:206 M
总下载量:203 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.36-1.el7.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY                                                                                 ]  0.0 B/s | 238 kB  --:--:-- ETA 
mysql-community-common-5.7.36-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mysql-community-common-5.7.36-1.el7.x86_64.rpm                                                                                                                                                                                                  | 310 kB  00:00:01     
(2/5): mysql-community-libs-5.7.36-1.el7.x86_64.rpm                                                                                                                                                                                                    | 2.4 MB  00:00:01     
(3/5): mysql-community-libs-compat-5.7.36-1.el7.x86_64.rpm                                                                                                                                                                                             | 1.2 MB  00:00:01     
(4/5): mysql-community-client-5.7.36-1.el7.x86_64.rpm                                                                                                                                                                                                  |  25 MB  00:00:05     
(5/5): mysql-community-server-5.7.36-1.el7.x86_64.rpm                                                                                                                                                                                                  | 174 MB  00:00:07     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                                           18 MB/s | 203 MB  00:00:11     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
 用户ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 指纹       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 软件包     : mysql80-community-release-el7-3.noarch (installed)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
warning: /var/cache/yum/x86_64/7/base/packages/postfix-2.10.1-9.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : mysql-community-common-5.7.36-1.el7.x86_64                                                                                                                                                                                                                1/8 
  正在安装    : mysql-community-libs-5.7.36-1.el7.x86_64                                                                                                                                                                                                                  2/8 
  正在安装    : mysql-community-client-5.7.36-1.el7.x86_64                                                                                                                                                                                                                3/8 
  正在安装    : mysql-community-libs-compat-5.7.36-1.el7.x86_64                                                                                                                                                                                                           4/8 
  正在更新    : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                                                                                                             5/8 
  正在安装    : mysql-community-server-5.7.36-1.el7.x86_64                                                                                                                                                                                                                6/8 
  清理        : 2:postfix-2.10.1-7.el7.x86_64                                                                                                                                                                                                                             7/8 
  正在删除    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                                                                                                                                                      8/8 
warning: file /usr/lib64/mysql/plugin/mysql_clear_password.so: remove failed: No such file or directory
warning: file /usr/lib64/mysql/plugin/dialog.so: remove failed: No such file or directory
warning: file /usr/lib64/mysql/libmysqlclient.so.18.0.0: remove failed: No such file or directory
  验证中      : mysql-community-libs-5.7.36-1.el7.x86_64                                                                                                                                                                                                                  1/8 
  验证中      : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                                                                                                             2/8 
  验证中      : mysql-community-common-5.7.36-1.el7.x86_64                                                                                                                                                                                                                3/8 
  验证中      : mysql-community-server-5.7.36-1.el7.x86_64                                                                                                                                                                                                                4/8 
  验证中      : mysql-community-client-5.7.36-1.el7.x86_64                                                                                                                                                                                                                5/8 
  验证中      : mysql-community-libs-compat-5.7.36-1.el7.x86_64                                                                                                                                                                                                           6/8 
  验证中      : 2:postfix-2.10.1-7.el7.x86_64                                                                                                                                                                                                                             7/8 
  验证中      : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                                                                                                                                                      8/8 

已安装:
  mysql-community-libs.x86_64 0:5.7.36-1.el7                                            mysql-community-libs-compat.x86_64 0:5.7.36-1.el7                                            mysql-community-server.x86_64 0:5.7.36-1.el7                                           

作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.36-1.el7                                                                                          mysql-community-common.x86_64 0:5.7.36-1.el7                                                                                         

作为依赖被升级:
  postfix.x86_64 2:2.10.1-9.el7                                                                                                                                                                                                                                               

替代:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5                                                                                                                                                                                                                                        

完毕!

9.启动mysql:

systemctl start mysqld.service #启动mysql
systemctl status mysqld.service #查看mysql的启动状态

10.停止mysql

systemctl stop mysqld.service

11.重启

systemctl restart mysqld.service

12.初始密码:

grep 'temporary password' /var/log/mysqld.log
2021-11-03T02:07:08.150670Z 1 [Note] A temporary password is generated for root@localhost: =046P:(Jp.vc

13.打开并登录mysql,修改密码。

mysql -uroot -p 
password:
#修改密码,情况1:
mysql> set password for root@localhost = password('123456'); #创建密码,root的
#提示内容:
mysql> ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

#重置密码,情况2:
mysql> ALTER USER 'root'@'localhost' identified by '123456';
mysql> ERROR 1819 (HY000): Your password does not satisfy the current policy requirements;#密码不安全
mysql> set global validate_password_policy=0; #修改密码的等级
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;#修改密码的长度限制
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' identified by '123456';#执行修改密码
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
mysql> mysql -uroot -p123456

#修改密码,情况3
mysql> ues mysql;
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost'; #设置密码
mysql> fluch privileges; #刷新权限
mysql> quit;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丨土豆丨

谢谢您的鼓励,我会继续努力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值