wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar
[root@study selinux]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@study selinux]# rpm -e --nodeps mariadb-libs
[root@study selinux]# rpm -qa|grep mariadb
tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar
yum -y install net-tools
rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs*
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
##可能你也会报以下的错
warning: mysql-community-server-8.0.13-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-8.0.13-1.el7.x86_64
perl(Getopt::Long) is needed by mysql-community-server-8.0.13-1.el7.x86_64
perl(strict) is needed by mysql-community-server-8.0.13-1.el7.x86_64
### 安装缺失的perl依赖包
yum install perl
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
systemctl start mysqld.service
grep 'temporary password' /var/log/mysqld.log
#记住下面显示的最后那些字符,那就是你的数据库密码
2018-11-16T15:15:20.149816Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: J/V3,F-pa;>X
#来吧试一下登录
mysql -uroot -p
[root@study data]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password: $RFV5tgb
Re-enter new password: $RFV5tgb
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_dictionary_file | | ##插件用于验证密码强度的字典文件路径。
| validate_password_length | 8 | ##密码最小长度,参数默认为8,
| validate_password_mixed_case_count | 1 |##密码至少要包含的小写字母个数和大写字母个数。
| validate_password_number_count | 1 | ##密码至少要包含的数字个数。
| validate_password.policy | MEDIUM | ##密码强度检查等级
| validate_password_special_char_count | 1 | ##密码至少要包含的特殊字符数。
+--------------------------------------+--------+
6 rows in set (0.08 sec)
我们主要改的位置为
validate_password.policy 密码强度检查等级。
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
有以下取值:
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 |
更改:(请注意看好你的字段,有的字段是 validate_password_policy)
set global validate_password.policy=0;
Query OK, 0 rows affected (0.05 sec)
set password for 用户名@localhost = password('新密码');
因为mysql8.0以后更改方式发生了改变,在此特地记一下。
#使用 mysql库
use mysql;
#查看要更改的账号
select Host,User from user where user='root';
#更改host为 % 表示全部
update user set Host='%' where User ='root';
#刷新
FLUSH PRIVILEGES;