vlambda博客
学习文章列表

CentOS7完美安装MySQL8教程



第一步:检查mysql是否安装

rpm -qa | grep mysql


#如果已安装先卸载

yum remove mysql-xxx-xxx


#查找卸载残余文件

find / -name mysql


#强制删除残余文件

rm -rf /var/lib/mysql


#查看是否安装mariadb(有冲突)

rpm -pa | grep mariadb


#如果已安装先卸载

yum -y remove mariadb-libs.x86_64

第二步:开始下载最新mysql的rpm包

wget http://dev.mysql.com/get/Downloads/mysql80-community-release-el7-3.noarch.rpm


#安装rpm

rpm -ivh mysql80-community-release-el7-3.noarch.rpm


#安装mysql

yum install mysql-community-server


#安装完毕后默认配置文件路径:

配置文件:/etc/my.cnf

日志文件:/var/log/var/log/mysqld.log

服务启动脚本:

/usr/lib/systemd/system/mysqld.service

Socket文件:/var/run/mysqld/mysqld.pid

第三步:启动服务并且设置开机自动启动

#这是centos7的命令

systemctl start mysqld.service 

systemctl enable mysqld.service

第四步:配置MySQL

#修改mysql配置文件


vim /etc/my.cnf


#修改密码,开启跳过默认密码


#配置文件本来就有注释打开即可


default-authentication-plugin=mysql_native_password


symbolic-links=0

skip-grant-tables


#每次修改完配文件请重复运行此重启命令


systemctl restart mysqld


温馨提示:

#停止服务命令是:

systemctl stop mysqld


第五步:登录MySQL、修改密码,添加用户,授权用户

#1登录mysql


mysql -uroot -p


#2先将密码更新成空


update user set authentication_string='' where user='root';


#3然后把配置文件之前设置的跳过密码注释掉(重启mysql)


#4重新连接mysql后会提示先重置密码才能继续操作


#5重置密码(注:这里设置密码太弱会提示不满足安全规则)


alter user 'root'@'localhost' identified by '12345678@Qwe';


#6设置密码加密方式永不过期


ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678@Qwe' PASSWORD EXPIRE NEVER;


# 7修改加密方式为mysql_native_password


ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678@Qwe';


#创建aaa用户


CREATE USER 'aaa'@'%' IDENTIFIED BY '12345678@Qaa';


#用户授权


GRANT EXECUTE,INSERT,SELECT,UPDATE ON * TO 'aaa'@'%';

GRANT ALL PRIVILEGES ON *.* TO 'aaa'@'%' WITH GRANT OPTION


#查看用户


select host, user, authentication_string, plugin from user;


#查看创建&授权


SHOW CREATE USER aaa;

SHOW GRANTS FOR aaa;


#修改mysql配置后请刷新


flush privileges;

End

点分享
点点赞
点在看