Centos 离线安装mysql5.7.32

1.Centos 离线安装mysql5.7.32

1.安装新版mysql前,需将系统自带的mariadb-lib卸载。
    rpm -qa|grep mariadb
    rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2.查看该操作系统上是否已经安装了mysql数据库
    rpm -qa | grep mysql
    rpm -ev mysql-community-libs-5.7.32-1.el6.x86_64 --nodeps // 强力删除模式
    查看卸载是否成功 
    rpm -qa | grep mysql
3.上传压缩包并解压
(官网下载地址:
centos7
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
centos6
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.32-1.el6.x86_64.rpm-bundle.tar)
 
解压后得到如下安装包:
 tar -xvf mysql-5.7.32-1.el6.x86_64.rpm-bundle.tar
 
4.使用rpm -ivh命令依次进行安装;以下步骤需要root权限。且因包之间的依赖关系,各rpm命令必须按序执行。
    rpm -ivh  mysql-community-common-5.7.32-1.el6.x86_64.rpm
    rpm -ivh  mysql-community-libs-5.7.32-1.el6.x86_64.rpm 
    rpm -ivh  mysql-community-client-5.7.32-1.el6.x86_64.rpm 
    rpm -ivh  mysql-community-server-5.7.32-1.el6.x86_64.rpm 
安装成功后,也可把安装文件和临时文件删除。
rm mysql-5.7.32-1.el6.x86_64.rpm-bundle.tar
5.创建用户和用户组
groupadd mysql
useradd -g mysql mysql
mkdir -p /var/run/mysql 
mkdir -p /var/log/mysql 
chown -R mysql:mysql /var/log/mysql 
chown -R mysql:mysql /var/run/mysql 
注:/etc/my.cnf中没有basedir路径,需要添加 
basedir=/usr/local/mysql
explicit_defaults_for_timestamp=true
6. 初始化数据库
// 初始化,指定datadir
cd /usr/bin/
chown -R mysql:mysql  /var/lib/mysql
 mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysql
// 初始化,执行生会在/var/log/mysqld.log生成随机密码,再去找临时密码
grep 'temporary password' /var/log/mysqld.log

 service mysqld restart 
// 重启mysql
7.登录mysql并查看版本号
 mysql -uroot -p 
8.修改root用户密码:
 UPDATE mysql.user SET authentication_string = password('your-password') WHERE host = 'localhost' AND user = 'root';


2.安全设置

2.1安装密码校验插件

查看当前mysql安装的插件信息
mysql> show plugins;
查看插件位置
mysql>show variables like 'plugin_dir';

vi /etc/my.cnf
# 插件位置
plugin_dir=/usr/local/mysql/lib/plugin 
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"

#取消验证
set global validate_password_policy=0;
set global validate_password_length=1;

#设置远程连接
grant all privileges on *.* to 'user'@'%' identified by '123456789' with grant option;

#添加用户名和密码
CREATE USER test@localhost IDENTIFIED BY 'test';
grant all privileges on test.* to test@% identified by '1234';

# 设置权限
 grant all on 数据库名.* to 用户名;
//刷新系统权限表
mysql>flush privileges;

#更换周期要求(90-180天)
use mysql;
update user set password_lifetime =180 where user ='user';
select password_lifetime from  user where user ='root';

#设置用户密码复杂度(数字、大小写字母和特殊字符混合)、最小长度(8位以上)
set global validate_password_policy=LOW;
set global validate_password_length =9;
flush privileges;

alter user user() identified by "123456789";

show variables like '%validate_password%'; 
查看密码复杂度和最小长度要求
show variables like 'default_password_lifetime';
查看密码有效期

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页