CentOS7使用rpm安装MySQL8

1. 到官网下载最新的的安装包:

 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

2. 卸载CentOS7自带的MariaDB依赖:

[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

3. 解压下载的安装包

 tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

4. 安装net-tools

 yum -y install net-tools

5. 依次安装mysql包

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

6. 启动mysql,获取默认root密码,登录mysql数据库

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

7. 初始化mysql(若登录成功了可以不再初始化,就用呗)

[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!

8. 更改密码安全强度级别

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,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

有以下取值:

PolicyTests Performed
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONGLength; 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('新密码');  

9. 更改某一用户可在非本机上登陆的方法

因为mysql8.0以后更改方式发生了改变,在此特地记一下。

#使用 mysql库
use mysql;
#查看要更改的账号
select Host,User from user where user='root';
#更改host为 % 表示全部
update user set Host='%' where User ='root';
#刷新
FLUSH PRIVILEGES;
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值