Mysql Rpm包安装
操作系统:
CentOS7
Mysql版本 5.7.28
一、删除CentOS系统本来有的 mariadb数据库和它的配置文件
yum remove mariadb
rm -rf /etc/my*
rm -rf /var/log/mysql*
rm -rf /var/lib/mysql*
二、解压Mysql压缩包
tar vxf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
三、创建mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
四、安装Mysql
方法一、依次安装下列包
rpm -ivh mysql-community-common-*.rpm
rpm -ivh mysql-community-libs-*.rpm
rpm -ivh mysql-community-client*.rpm
rpm -ivh mysql-community-server-5.7*.rpm
方法二、使用yum解决依赖关系
yum localinstall mysql-community* -y
五、初始化mysql
mysqld --initialize --user=mysql
六、查看mysql初始化的密码
cat /var/log/mysqld.log
七、启动mysql
systemctl start mysqld
systemctl enable mysqld
八、使用mysql初始的密码等入,并更改mysql的root用户密码
mysql -uroot -pviSUuoZp_9O=
更改密码策略(以下为mysql5.7更改)
set global validate_password_policy=0;
set global validate_password_length=4;
flush privileges;
alter user 'root'@'localhost' identified by 'root';
补充:更改密码策略(以下为mysql8更改)
# 变更密码规则
set global validate_password.policy=0;
#修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
#更新一下用户的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
# 授权远程访问
grant all privileges on *.* to 'root'@'%' with grant option;
# 刷新权限
FLUSH PRIVILEGES;