Redhat7.4安装mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar重要步骤详解
1、到MySQL官网下载,直接点击No thanks, just start my download.下载即可
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”,而自己又不想设置那么复杂的密码,看最后步骤修改密码校验。在这里设置密码校验的话,flush privileges;会重置原先从状态。
注意:
现有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$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | 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的权限:select Grant_priv,Super_priv from user where user = 'root' and host = '%';(如果你是指定的IP权限,这里的%换成指定的IP),结果改为“Y”,我是设置全部为“Y”,建议不要
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 |
+--------------------------------------+--------+
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)
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634961.html