Centos7安装mysql8


记录安装及配置过程,以方便下次的安装。

开始安装

1.配置Mysql 8.0安装源
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
1.配置Mysql 8.0安装源
sudo yum --enablerepo=mysql80-community install mysql-community-server

然后根据相应的提示,输入Y即可

Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-8.0.21-1.el7.x86_64                                                                                                                                  1/9 
  Installing : mysql-community-libs-8.0.21-1.el7.x86_64                                                                                                                                    2/9 
  Installing : mysql-community-client-8.0.21-1.el7.x86_64                                                                                                                                  3/9 
  Installing : mysql-community-libs-compat-8.0.21-1.el7.x86_64                                                                                                                             4/9 
  Installing : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                                                   5/9 
  Installing : mysql-community-server-8.0.21-1.el7.x86_64                                                                                                                                  6/9 
  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                               7/9 
  Cleanup    : 2:postfix-2.10.1-7.el7.x86_64                                                                                                                                               8/9 
  Erasing    : 1:mariadb-libs-5.5.64-1.el7.x86_64                                                                                                                                          9/9 
  Verifying  : mysql-community-server-8.0.21-1.el7.x86_64                                                                                                                                  1/9 
  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                               2/9 
  Verifying  : mysql-community-libs-8.0.21-1.el7.x86_64                                                                                                                                    3/9 
  Verifying  : mysql-community-client-8.0.21-1.el7.x86_64                                                                                                                                  4/9 
  Verifying  : mysql-community-libs-compat-8.0.21-1.el7.x86_64                                                                                                                             5/9 
  Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                                                   6/9 
  Verifying  : mysql-community-common-8.0.21-1.el7.x86_64                                                                                                                                  7/9 
  Verifying  : 1:mariadb-libs-5.5.64-1.el7.x86_64                                                                                                                                          8/9 
  Verifying  : 2:postfix-2.10.1-7.el7.x86_64                                                                                                                                               9/9 

Installed:
  mysql-community-libs.x86_64 0:8.0.21-1.el7                  mysql-community-libs-compat.x86_64 0:8.0.21-1.el7                  mysql-community-server.x86_64 0:8.0.21-1.el7                 

Dependency Installed:
  mysql-community-client.x86_64 0:8.0.21-1.el7                   mysql-community-common.x86_64 0:8.0.21-1.el7                   net-tools.x86_64 0:2.0-0.25.20131004git.el7                  

Dependency Updated:
  postfix.x86_64 2:2.10.1-9.el7                                                                                                                                                                

Replaced:
  mariadb-libs.x86_64 1:5.5.64-1.el7                                                                                                                                                           

Complete!

安装完成!

启动

1.启动mysql服务
systemctl start mysqld
2.查看mysql服务运行状态
[root@localhost docker]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-08-08 21:21:43 CST; 59s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2855 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2933 (mysqld)
   Status: "Server is operational"
    Tasks: 39
   Memory: 279.0M
   CGroup: /system.slice/mysqld.service
           └─2933 /usr/sbin/mysqld

Aug 08 21:21:32 localhost.localdomain systemd[1]: Starting MySQL Server...
Aug 08 21:21:43 localhost.localdomain systemd[1]: Started MySQL Server.
3.查看root临时密码

输入如下命令,查看安装mysql生成的临时密码

[root@localhost docker]# grep "A temporary password" /var/log/mysqld.log
2020-08-08T13:21:36.082946Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: SGwgpYSy5v?r

SGwgpYSy5v?r就是默认初始密码

4.登录
[root@localhost docker]# mysql -uroot -p
Enter password: #输入查询出来额默认密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21

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> 

5.修改密码
alter user user() identified by "123456";

会出现:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements。
但是当你执行:SHOW VARIABLES LIKE ‘validate_password.%’;语句查看password的相关规则时,ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.,意思就是你必须先修改密码才可以执行别的命令
所以我们先设置一个复杂密码,例如之前查到的默认密码

alter user user() identified by "SGwgpYSy5v?r";

现在可以查看并修改password的规则了

mysql> SHOW VARIABLES LIKE 'validate_password.%' #查询规则
    -> ;
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.03 sec)
#开始修改默认的password规则
mysql> set global validate_password.length=6; #密码的最小长度默认是8,改成6
Query OK, 0 rows affected (0.01 sec)

mysql> set global validate_password.policy=0; #验证密码的复杂程度改成0
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.check_user_name=off; #用户名检查关掉
Query OK, 0 rows affected (0.00 sec)

mysql> alter user user() identified by "123456"; #这下再修改成简单密码就可以了
Query OK, 0 rows affected (0.00 sec)

mysql> 

6.开启远程访问

先选择mysql表

mysql> use mysql
Database changed

查询root的访问权限,通过查询可以看出root的访问只允许 localhost;

mysql> select host, user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

修改权限,并查看是否成功

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)

mysql> select host, user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.01 sec)
#修改成功,localhost变成%
注意,必须执行以下命令,否则不无法成功
FLUSH PRIVILEGES;
7.开启mysql端口号
[root@localhost tmac]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost tmac]# firewall-cmd --reload #重新加载防火墙
success

全部完成可以使用可视化工具远程登录mysql了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值