当前位置:   article > 正文

yum方式安装MySQL_[root@admin local]# yum-config-manager --disable m

[root@admin local]# yum-config-manager --disable mysql80-community loaded pl

一、yum安装前提
1.需要yum网络源
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo
2.关闭防火墙
[root@localhost ~]# systemctl status firewalld
● 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)
3.关闭selinux
[root@localhost ~]# getenforce selinux
Disabled
4.下载MySQL安装包
mysql的官方网站:www.mysql.com
MySQL 版本号:MySQL 5.7.27
下载MySQL安装包操作如下:
(1)downloads下载,找到网页最下面MySQL Community(GPL)Downloads,点进去

在这里插入图片描述
(2)跳转到此页面,找到MySQL Yum Repository ,点击

在这里插入图片描述
(3)在此页面找到Red Hat Enterprise Linux7,RPM Pakage,点击Download
在这里插入图片描述
(4)跳转到此页面,鼠标右键点击No thanks,just start my download,选择复制地链接,复制MySQL安装包的链接地址

在这里插入图片描述
二、下载MySQL
1.下载MySQL安装包 (MySQL安装包的链接地址粘贴)
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
或者下载到本地上传到服务器
[root@localhost ~]# ls
mysql80-community-release-el7-3.noarch.rpm
2.安装mysql的yum仓库
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo mysql-community.repo mysql-community-source.repo
3.配置yum源
[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo

在这里插入图片描述
使用MySQL5.7版本的yum源将MySQL5.7版本的enabled改为1,MySQL8.0版本的enabled改为0。
或者
[root@localhost ~]# yum -y install yum-utils #安装yum工具包
[root@localhost ~]# yum-config-manager --enable mysql57-community 将禁用的yum源库启用
[root@localhost ~]# yum-config-manager --disable mysql80-community 将启用的yum源库禁用
4.安装数据库
[root@localhost ~]# yum install -y mysql-community-server
启动服务
[root@localhost ~]# systemctl start mysqld
设置开机启动
[root@localhost ~]# systemctl enable mysqld
查看服务状态
[root@localhost ~]# systemctl status mysqld

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2020-12-22 21:20:47 CST; 2min 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 91323 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─91323 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

1222 21:20:41 localhost.localdomain systemd[1]: Starting MySQL Server...
1222 21:20:47 localhost.localdomain systemd[1]: Started MySQL Server.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

三、登录数据库
1.查找数据库密码
密码保存在日志文件中
[root@localhost ~]# grep password /var/log/mysqld.log
2020-12-22T13:20:43.195538Z 1 [Note] A temporary password is generated for root@localhost: I)XzKLMsZ5HD
2.修改密码并登录数据库
两种方式:
(1)第一种:
mysqladmin -u root -p’旧密码’ password ‘新密码’
[root@localhost ~]# mysqladmin -uroot -p’I)XzKLMsZ5HD’ password ‘Sunny@123456’
注:修改密码必须大小写数字和特殊符号都有。

使用新密码登录 数据库即可:
[root@localhost ~]# mysql -uroot -p'Sunny@123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> exit //退出数据库
Bye
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

(2)第二种:
先用旧密码登录数据库:
[root@localhost ~]# mysql -uroot -p’I)XzKLMsZ5HD’ #登录

mysql> alter user ‘root’@‘localhost’ identified by ‘XingXing@123456’; #修改密码
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges; #刷新权限表
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

使用新密码登录数据库即可:
[root@localhost ~]# mysql -uroot -p'XingXing@123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> exit
Bye
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/181044
推荐阅读
相关标签
  

闽ICP备14008679号