小白centos7安装mysql8步骤说明

先看一下我的安装环境
在这里插入图片描述
MySQL版本
链接 https://dev.mysql.com/downloads/repo/yum/
点击跳转下方图片地址链接
在这里插入图片描述
这个rpm可以使用wget下载

wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm 

也可以点击DownLoad下载后在导入centos7中

下载完成后使用yum命令本地安装yum源

yum localinstall mysql80-community-release-el7-1.noarch.rpm

执行完毕后使用下面的命令检查是否安装成功

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

看到类似下图说明安装成功

[root@localhost 桌面]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64        MySQL Connectors Community         0
mysql-tools-community/x86_64             MySQL Tools Community              0
mysql80-community/x86_64                 MySQL 8.0 Community Server         0

使用下面命令进行安装

yum install -y mysql-community-server

安装过程

[root@localhost 桌面]# yum install -y mysql-community-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.cqu.edu.cn
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
mysql-connectors-community                               | 2.5 kB     00:00     
mysql-tools-community                                    | 2.5 kB     00:00     
mysql80-community                                        | 2.5 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/7): extras/7/x86_64/primary_db                          | 205 kB   00:02     
(2/7): base/7/x86_64/group_gz                              | 166 kB   00:02     
(3/7): mysql-connectors-community/x86_64/primary_db        |  29 kB   00:02     
(4/7): mysql-tools-community/x86_64/primary_db             |  48 kB   00:02     
(5/7): mysql80-community/x86_64/primary_db                 |  35 kB   00:00     
(6/7): base/7/x86_64/primary_db                            | 5.9 MB   00:03     
(7/7): updates/7/x86_64/primary_db                         | 6.0 MB   00:01     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.8.0.13-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.13-1.el7,它被软件包 mysql-community-server-8.0.13-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.0,它被软件包 mysql-community-server-8.0.13-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.8.0.13-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.0,它被软件包 mysql-community-client-8.0.13-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.8.0.13-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.56-2.el7 将被 取代
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要
---> 软件包 mysql-community-libs.x86_64.0.8.0.13-1.el7 将被 舍弃
--> 正在检查事务
---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.13-1.el7 将被 舍弃
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                      架构    版本             源                  大小
================================================================================
正在安装:
 mysql-community-libs         x86_64  8.0.13-1.el7     mysql80-community  2.3 M
      替换  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat  x86_64  8.0.13-1.el7     mysql80-community  2.1 M
      替换  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server       x86_64  8.0.13-1.el7     mysql80-community  381 M
为依赖而安装:
 mysql-community-client       x86_64  8.0.13-1.el7     mysql80-community   26 M
 mysql-community-common       x86_64  8.0.13-1.el7     mysql80-community  554 k

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

总下载量:412 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.13-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
mysql-community-common-8.0.13-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mysql-community-common-8.0.13-1.el7.x86_64.rpm      | 554 kB   00:00     
(2/5): mysql-community-libs-8.0.13-1.el7.x86_64.rpm        | 2.3 MB   00:00     
(3/5): mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm | 2.1 MB   00:00     
(4/5): mysql-community-client-8.0.13-1.el7.x86_64.rpm      |  26 MB   00:06     
(5/5): mysql-community-server-8.0.13-1.el7.x86_64.rpm      | 381 MB   00:39     
--------------------------------------------------------------------------------
总计                                                10 MB/s | 412 MB  00:41     
从 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-1.noarch (installed)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mysql-community-common-8.0.13-1.el7.x86_64                  1/6 
  正在安装    : mysql-community-libs-8.0.13-1.el7.x86_64                    2/6 
  正在安装    : mysql-community-client-8.0.13-1.el7.x86_64                  3/6 
  正在安装    : mysql-community-server-8.0.13-1.el7.x86_64                  4/6 
  正在安装    : mysql-community-libs-compat-8.0.13-1.el7.x86_64             5/6 
  正在删除    : 1:mariadb-libs-5.5.56-2.el7.x86_64                          6/6 
  验证中      : mysql-community-libs-compat-8.0.13-1.el7.x86_64             1/6 
  验证中      : mysql-community-libs-8.0.13-1.el7.x86_64                    2/6 
  验证中      : mysql-community-client-8.0.13-1.el7.x86_64                  3/6 
  验证中      : mysql-community-server-8.0.13-1.el7.x86_64                  4/6 
  验证中      : mysql-community-common-8.0.13-1.el7.x86_64                  5/6 
  验证中      : 1:mariadb-libs-5.5.56-2.el7.x86_64                          6/6 

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

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

替代:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                            

完毕!

使用systemctl start mysqld命令启动
使用systemctl status mysqld查看服务启动状态
服务启动过程

[root@localhost 桌面]# systemctl start 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 四 2018-11-22 19:38:59 CST; 1min 39s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 55058 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 55140 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 37
   CGroup: /system.slice/mysqld.service
           └─55140 /usr/sbin/mysqld

11月 22 19:38:36 localhost.localdomain systemd[1]: Starting MySQL Server...
11月 22 19:38:59 localhost.localdomain systemd[1]: Started MySQL Server.

设置开机启动

systemctl enable mysqld
systemctl daemon-reload

修改root的默认密码
在修改密码之前要先做一件事,就是找到mysql的配置文件(vim /etc/my.cnf)↓
把密码的加密方式改成之前版本的,8.0版本更换了密码的加密方式,我们就先用旧的
找到Mysql的配置文件并编辑

vim /etc/my.cnf

找到 default-authentication-plugin=mysql_native_password
打开注释,保存退出编辑。

查询密码命令

 grep 'temporary password' /var/log/mysqld.log

查询过程

[root@localhost 桌面]# grep 'temporary password' /var/log/mysqld.log
2018-11-22T11:38:51.559334Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 5(Y2Ly+Cs:Q*

5(Y2Ly+Cs:Q*就是我的初始化登录密码

登录mysql

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

Copyright (c) 2000, 2018, 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> 

登录后不允许进行任何操作,我们需要先修改密码,否则一直会报下面这个错误

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

密码修改命令,如果报错可能是密码设置的简单了

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

如果不想输入太复杂的密码,可以通过下面的方式降低密码复杂度,这样密码就可以随便设置了

查看密码设置策略

SHOW VARIABLES LIKE 'validate_password%';

得到下面结果

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 4     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.06 sec)

参数解释
validate_password.check_user_name
用户名检测
validate_password_dictionary_file
插件用于验证密码强度的字典文件路径。
validate_password_length
密码最小长度
validate_password_mixed_case_count
密码至少要包含的小写字母个数和大写字母个数。
validate_password_number_count
密码至少要包含的数字个数。
validate_password_policy
密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。有以下取值:
Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
validate_password_special_char_count
密码至少要包含的特殊字符数。

我们用下面两条命令修改密码强度限制
设置密码强度级别,三个数字分别对应低,中,高三个级别.我们设置成"低"也就是0

set global validate_password.policy=0;

这个是设置密码长度的,不能低于4位,根据需要自己设置长度.

set global validate_password.length=4;

这个是修改密码的命令,给root用户本地登录设置密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '我的密码';

增加远程连接用户

创建用户(user:用户名;%:任意ip,也可以指定)

CREATE USER 'testname'@'%' IDENTIFIED BY 'testpwd';

授权,默认创建的用户权限是usage,就是无权限,只能登录而已
(all:所有权限,这里有select,update等等权限,可以去搜一下;后面的
.*:指定数据库.指定表,这里是所有;to后面就是你刚才创建的用户)
*

grant all on *.* to 'testname'@'%';

注意:用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:
username与host 根据情况进行修改

GRANT all ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION; 

最后刷新一下

FLUSH PRIVILEGES;

使用Navicat 远程登录
更改加密方式:

ALTER USER 'testname'@'%' IDENTIFIED BY 'testpwd' PASSWORD EXPIRE NEVER;

更改密码:testpwd

ALTER USER 'testname'@'%' IDENTIFIED WITH mysql_native_password BY 'testpwd';

最后刷新一下

FLUSH PRIVILEGES;

防火墙设置,让 3306 端口对外可访问

iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# 查看规则是否生效
iptables -L -n # 或者: service iptables status
 
# 此时生产环境是不安全的,远程管理之后应该关闭端口,删除之前添加的规则
iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
注意:上面iptables添加/删除规则都是临时的,如果需要重启后也生效,需要保存修改:
service iptables save # 或者: /etc/init.d/iptables save

或者

vi /etc/sysconfig/iptables # 加上下面这行规则也是可以的
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

走到无路可退

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值