[网上教程转载整理]CentOS 7 下 MySQL 5.7 的安装与配置(yum)

1.安装yum源

下载mysql yum源:

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装:

yum localinstall mysql57-community-release-el7-11.noarch.rpm

检查yum安装是否成功:

yum repolist enabled | grep "mysql.*-community.*"

如果成功显示内容如下:

2.yum 安装mysql

yum install -y mysql-community-server

可能会出现Delta RPMs disabled because /usr/bin/applydeltarpm not installed警告导致安装失败,可以在执行安装命令前执行下面两个命令

yum provides '*/applydeltarpm'
yum -y  install deltarpm

3.启动mysql服务

systemctl start mysqld

查看mysql状态

systemctl status mysqld

设置开机启动

systemctl enable mysqld

systemctl daemon-reload

mysql 安装完成之后,生成的默认密码在 /var/log/mysqld.log 文件中。使用 grep 命令找到日志中的密码。

grep 'temporary password' /var/log/mysqld.log

 通过初始密码登录后,使用以下命令修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassWord';

查看密码强度规则

SHOW VARIABLES LIKE 'validate_password%'; 

validate_password_dictionary_file 插件用于验证密码强度的字典文件路径。

validate_password_length 密码最小长度,参数默认为8,它有最小值的限制,最小值为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

validate_password_mixed_case_count 密码至少要包含的小写字母个数和大写字母个数。

validate_password_number_count 密码至少要包含的数字个数。

validate_password_policy 密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。有以下取值:
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      
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

validate_password_special_char_count 密码至少要包含的特殊字符数。

修改密码强度规则:

set global validate_password_policy=0; 
set global validate_password_mixed_case_count=0; 
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;

远程登录用户创建并授权 

grant all privileges on *.* to 'new username'@'host' identified by '(密文密码)';

flush privileges;

查看所有用户、密文密码、可登录地址

select user,authentication_string,host from user;

生成密文字符串

select password ('123123');  //生成密文字符串

修改密码

set password=password('123123');  //修改当前登陆用户密码
set password for 'username'@'host'=password('123456');  //修改其他用户密码
update mysql.user set authentication_string=password('abcabc') where user='root';//修改指定用户的密码
flush privileges;// 修改完成后刷新

用户授权

GRANT all privileges ON databasename.tablename TO 'username'@'host';// 授权所有权限
GRANT SELECT ON databasename.tablename TO 'username'@'host';//授权查询
REVOKE privilege ON databasename.tablename FROM 'username'@'host';//撤销权限
show grants for 'username'@'host';//查看用户权限信息

 

你可能感兴趣的:(MySQL,Linux,mysql,linux,centos,服务器)