当前位置: 移动技术网 > IT编程>数据库>Mysql > CentOS7.8安装mysql 8.0.20的教程详解

CentOS7.8安装mysql 8.0.20的教程详解

2020年06月14日  | 移动技术网IT编程  | 我要评论

林宏忠,超市低标价高收款,巴西创7大耻辱

一、安装mysql软件

下载并安装mysql官方的 yum repository,mysql版本8.0.20

wget -i -c 
http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

下载后直接yum安装

yum -y install mysql80-community-release-el7-3.noarch.rpm

安装mysql服务器

yum -y install mysql-community-server
[root@centos linux]# yum -y install mysql-community-server
loaded plugins: fastestmirror, langpacks
loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirror.lzu.edu.cn
 * updates: mirror.lzu.edu.cn
mysql-connectors-community            | 2.5 kb 00:00:00  
mysql-tools-community             | 2.5 kb 00:00:00  
mysql80-community              | 2.5 kb 00:00:00  
(1/3): mysql-connectors-community/x86_64/primary_db      | 57 kb 00:00:00  
mysql-tools-community/x86_64/p failed           b 00:51:07 eta 
http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/repodata/12bd1e8730cd532791529877bf5e7babbbb02879-primary.sqlite.bz2: [errno 12] timeout on http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/repodata/12bd1e8730cd532791529877bf5e7babbbb02879-primary.sqlite.bz2: (28, 'operation too slow. less than 1000 bytes/sec transferred the last 30 seconds')
trying other mirror.
(2/3): mysql-tools-community/x86_64/primary_db       | 72 kb 00:00:00  
mysql80-community/x86_64/prima failed           b 00:00:15 eta 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/repodata/833c637b3989c2dd5a079a045177d2f1c96e9c1e-primary.sqlite.bz2: [errno 12] timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/repodata/833c637b3989c2dd5a079a045177d2f1c96e9c1e-primary.sqlite.bz2: (28, 'operation too slow. less than 1000 bytes/sec transferred the last 30 seconds')
trying other mirror.
(3/3): mysql80-community/x86_64/primary_db        | 107 kb 00:00:00  
resolving dependencies
--> running transaction check
---> package mysql-community-server.x86_64 0:8.0.20-1.el7 will be installed
--> processing dependency: mysql-community-common(x86-64) = 8.0.20-1.el7 for package: mysql-community-server-8.0.20-1.el7.x86_64
--> processing dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.20-1.el7.x86_64
--> running transaction check
---> package mysql-community-client.x86_64 0:8.0.20-1.el7 will be installed
--> processing dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.20-1.el7.x86_64
---> package mysql-community-common.x86_64 0:8.0.20-1.el7 will be installed
--> running transaction check
---> package mariadb-libs.x86_64 1:5.5.65-1.el7 will be obsoleted
--> processing dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> processing dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
---> package mysql-community-libs.x86_64 0:8.0.20-1.el7 will be obsoleting
--> running transaction check
---> package mysql-community-libs-compat.x86_64 0:8.0.20-1.el7 will be obsoleting
--> finished dependency resolution
 
dependencies resolved
 
===============================================================================================
 package       arch  version    repository    size
===============================================================================================
installing:
 mysql-community-libs    x86_64  8.0.20-1.el7  mysql80-community  4.5 m
  replacing mariadb-libs.x86_64 1:5.5.65-1.el7
 mysql-community-libs-compat  x86_64  8.0.20-1.el7  mysql80-community  1.2 m
  replacing mariadb-libs.x86_64 1:5.5.65-1.el7
 mysql-community-server   x86_64  8.0.20-1.el7  mysql80-community  488 m
installing for dependencies:
 mysql-community-client   x86_64  8.0.20-1.el7  mysql80-community  47 m
 mysql-community-common   x86_64  8.0.20-1.el7  mysql80-community  609 k
 
transaction summary
===============================================================================================
install 3 packages (+2 dependent packages)
 
total download size: 541 m
is this ok [y/d/n]: y
downloading packages:
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.20-1.el7.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey
public key for mysql-community-common-8.0.20-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-8.0.20-1.el7.x86_64.rpm     | 609 kb 00:00:00  
(2/5): mysql-community-libs-8.0.20-1.el7.x86_64.rpm      | 4.5 mb 00:00:13  
(3/5): mysql-community-libs-compat-8.0.20-1.el7.x86_64.rpm    | 1.2 mb 00:00:04  
mysql-community-client-8.0.20- failed           b 00:22:23 eta 
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.20-1.el7.x86_64.rpm: [errno 12] timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.20-1.el7.x86_64.rpm: (28, 'operation too slow. less than 1000 bytes/sec transferred the last 30 seconds')
trying other mirror.
(4/5): mysql-community-server-8.0.20-1.el7.x86_64.rpm     | 488 mb 00:22:18  
(5/5): mysql-community-client-8.0.20-1.el7.x86_64.rpm     | 47 mb 00:01:57  
-----------------------------------------------------------------------------------------------
total               376 kb/s | 541 mb 00:24:34  
retrieving key from file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql
importing gpg key 0x5072e1f5:
 userid  : "mysql release engineering <mysql-build@oss.oracle.com>"
 fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 package : mysql80-community-release-el7-3.noarch (installed)
 from  : /etc/pki/rpm-gpg/rpm-gpg-key-mysql
is this ok [y/n]: y 
running transaction check
running transaction test
transaction test succeeded
running transaction
warning: rpmdb altered outside of yum.
 installing : mysql-community-common-8.0.20-1.el7.x86_64         1/6 
 installing : mysql-community-libs-8.0.20-1.el7.x86_64         2/6 
 installing : mysql-community-client-8.0.20-1.el7.x86_64         3/6 
 installing : mysql-community-server-8.0.20-1.el7.x86_64         4/6 
 installing : mysql-community-libs-compat-8.0.20-1.el7.x86_64        5/6 
 erasing : 1:mariadb-libs-5.5.65-1.el7.x86_64           6/6 
 verifying : mysql-community-libs-compat-8.0.20-1.el7.x86_64        1/6 
 verifying : mysql-community-common-8.0.20-1.el7.x86_64         2/6 
 verifying : mysql-community-server-8.0.20-1.el7.x86_64         3/6 
 verifying : mysql-community-client-8.0.20-1.el7.x86_64         4/6 
 verifying : mysql-community-libs-8.0.20-1.el7.x86_64         5/6 
 verifying : 1:mariadb-libs-5.5.65-1.el7.x86_64           6/6 
 
installed:
 mysql-community-libs.x86_64 0:8.0.20-1.el7             
 mysql-community-libs-compat.x86_64 0:8.0.20-1.el7           
 mysql-community-server.x86_64 0:8.0.20-1.el7             
 
dependency installed:
 mysql-community-client.x86_64 0:8.0.20-1.el7 mysql-community-common.x86_64 0:8.0.20-1.el7 
 
replaced:
 mariadb-libs.x86_64 1:5.5.65-1.el7 
 
complete!

安装完成后就会覆盖掉之前的mariadb

二、配置mysql数据库

启动mysql

systemctl start mysqld.service

查看mysql运行状态

systemctl status mysqld.service
● mysqld.service - mysql server
 loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
 active: active (running) since wed 2020-05-13 23:57:41 hkt; 18s ago
  docs: man:mysqld(8)
   http://dev.mysql.com/doc/refman/en/using-systemd.html
 process: 9563 execstartpre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/success)
 main pid: 9649 (mysqld)
 status: "server is operational"
 tasks: 39
 cgroup: /system.slice/mysqld.service
   └─9649 /usr/sbin/mysqld
 
may 13 23:57:34 centos.highning.com systemd[1]: starting mysql server...
may 13 23:57:41 centos.highning.com systemd[1]: started mysql server.

找出root初始密码

grep "password" /var/log/mysqld.log

2020-05-13t15:57:37.815353z 6 [note] [my-010454] [server] a temporary password is generated for : 9*cxxnrwhqml

进入数据库:

mysql -uroot -p

输入密码(密码是上面查询到的 ,/wsw6gif;eh ),此时不能操作数据库,必须修改密码之后才能操作数据库

alter user 'root'@'localhost' identified by 'new password';

其中‘new password'替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功

三、开启mysql的远程访问

执行以下命令开启远程访问限制(注意:下面命令开启的ip是 192.168.0.1,如要开启所有的,用%代替ip),mysql8.0和以前的版本不一样,不能用原来的命令同时授权和创建用户:

create user 'root'@'192.168.0.1' identified by 'password';
grant all privileges on *.* to 'root'@'192.168.0.1' with grant option;

再输入以下两行命令

flush privileges;
exit

四、为firewalld添加开放端口

添加mysql端口3306和tomcat端口8080

firewall-cmd --zone=public --add-port=3306/tcp --permanent
 
firewall-cmd --zone=public --add-port=8080/tcp --permanent

重新载入

firewall-cmd --reload

最后在windows下用mysql命令登录

microsoft windows [版本 10.0.18363.778]
(c) 2019 microsoft corporation。保留所有权利。
 
c:\users\highning>mysql -h 192.168.88.88 -p 3306 -u root -p
enter password: ********
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 10
server version: 8.0.20 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> show databases;
+--------------------+
| database   |
+--------------------+
| information_schema |
| mysql    |
| performance_schema |
| sys    |
+--------------------+
4 rows in set (0.00 sec)
 
mysql>

修改密码安全策略,改为low,密码长度最小6位

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.00 sec)
 
mysql> set global validate_password.policy=low;
query ok, 0 rows affected (0.00 sec)
 
mysql> set global validate_password.length=6;
query ok, 0 rows affected (0.00 sec)
 
mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| variable_name      | value |
+--------------------------------------+-------+
| validate_password.check_user_name | on |
| validate_password.dictionary_file |  |
| validate_password.length    | 6  |
| 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.00 sec)

关于 mysql 密码策略相关参数;

1)、validate_password.length  固定密码的总长度;

2)、validate_password_dictionary_file 指定密码验证的文件路径;

3)、validate_password_mixed_case_count  整个密码中至少要包含大/小写字母的总个数;

4)、validate_password_number_count  整个密码中至少要包含阿拉伯数字的个数;

5)、validate_password.policy 指定密码的强度验证等级,默认为 medium;

6)、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

关于 validate_password.policy 的取值:

low:只验证长度;

medium:验证长度、数字、大小写、特殊字符;

strong:验证长度、数字、大小写、特殊字符、字典文件;

总结

到此这篇关于centos7.8安装mysql 8.0.20的文章就介绍到这了,更多相关centos7.8安装mysql 8.0.20内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网