Redhat7.4安装mysql-8.0.18-1.el7.x86_64.rpm-bund。。。
1、到下载,直接点击下载即可
2、下载后,上传到服务器上,开始安装步骤
3、解压安装包:tar -xvf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar
4、安装顺序:common --> libs --> client --> server --> devel。(devel可不装)安装命令:rpm -ivh mysql-community-common-
8.0.15-1.el7.x86_64.rpm
当提⽰“mariadb-libs 被 mysql-community-libs-8.0.15-1.el7.x86_64 取代”,是lib和系统⾃带的冲突,删除后继续:yum remove mysql-libs -y
依赖缺失时“net-tools 被 mysql-community-server-8.0.15-1.el7.x86_64 需要”,直接安装缺失的依赖:yum install net-tools -y
5、到密码、登陆、修改密码
到安装⽇志:/var/log/mysqld.log
查看⽇志中的密码:0waB,#p6&2FH
[root@tts log]# cat mysqld.log
2019-11-08T07:07:16.206958Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 118997
2019-11-08T07:07:28.928232Z 5 [Note] [MY-010454] [Server] A temporary password is generated for
root@localhost: 0waB,#p6&2FH
6、重启MySQL服务:service mysqld restart 或者 /bin/systemctl restart mysqld.service(这⾥没有设置,只能⽤第⼆个⽅法启
动)
7、登陆:mysql -u root -p,密码是前⾯查看⽇志得到的 0waB,#p6&2FH
8、修改密码:mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '1qaz@WSX';
如果提⽰“Your password does not satisfy the current policy requirements”,⽽⾃⼰⼜不想设置那么复杂的密码,看最后步骤修改密码校验。在这⾥设置密码校验的话注意:
现有ALTER USER命令,把默认密码修改成符合MySQL的密码规则,然后,再到最后⼀步执⾏那三条命令,然后再⽤ALTER USER命令修改⾃⼰想要的密码即可。
友情提⽰:
密码简单会危害安全
9、开放所有ip地址都能访问:mysql> CREATE USER 'root'@'%' IDENTIFIED BY '1qaz@WSX';
1qaz@WSX是你⾃⼰设置的密码,若执⾏开放指定ip能访问,把%换成ip地址。
10、修改加密⽅式:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '1qaz@WSX';
MySQL默认是caching_sha2_password
11、开放防⽕墙端⼝
查看防⽕墙开放的端⼝。firewall-cmd --zone=public --list-ports
开启防⽕墙端⼝3306:firewall-cmd --zone=public --add-port=3306/tcp --permanent
12、刷新权限,验证数据库能否正常使⽤
mysql> flush privileges; //刷新MySQL的系统权限相关表
Query OK, 0 rows affected (0.01 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | *58319282EAB9E38D49CA25844B73DA62C80C2ABC | mysql_native_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | | localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVAL
IDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$]%*L`u W^3z'6J1gPpSwRHxYVZNCfg6Z4cVY7XVYaZ92e.u0U0YmCmhveiz2 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)
[root@localhost ~]# firewall-cmd --zone=public --list-ports
80/tcp 8080/tcp 8081/tcp 8761/tcp
[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@localhost ~]# firewall-cmd --zone=public --list-ports
80/tcp 8080/tcp 3306/tcp 8081/tcp 8761/tcp
13、远程连接数据库授权
创建数据库:CREATE SCHEMA `dyh` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
授权远程连接:grant all on dyh.* to 'root'@'%' identified by '1qaz@WSX' with grant option;
如果在客户端创建表时报错:"Error 1142: CREATE command denied to user 'root'@'192.168.85.1' for table 'test_table'",查看user表中'root'@'%'没有grant的权限
mysql> CREATE SCHEMA `dyh` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
Query OK, 1 row affected, 2 warnings (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| dyh |
+--------------------+
5 rows in set (0.00 sec)
mysql> grant all on dyh.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> update mysql.user set Grant_priv='Y',Super_priv='Y' ;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 5 Changed: 3 Warnings: 0
mysql> select host,Grant_priv,Super_priv from mysql.user ;
+-----------+------------+------------+
| host | Grant_priv | Super_priv |
+-----------+------------+------------+
| % | Y | Y |
| localhost | Y | Y |
| localhost | Y | Y |
| localhost | Y | Y |
| localhost | Y | Y |
+-----------+------------+------------+
5 rows in set (0.00 sec)
mysql> quit
Bye
[root@localhost ~]# /bin/systemctl restart mysqld.service
可以访问你的远程操作数据库了
附录:
设置登陆密码的复杂度。在设置登陆密码时,总会提⽰:“Your password does not satisfy the current policy requirements”。
⾸先查看密码规则: SHOW VARIABLES LIKE 'validate_password%'; length设置:set global validate_password.length=4;
policy设置:set global validate_password.policy=0;
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 |
mysql下载libs包的网址+--------------------------------------+--------+
7 rows in set (0.01 sec)
mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.policy=0;
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 | 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.00 sec)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论