本文介绍使用rpm包安装mysql,
以 mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar 为例;
1.下载
MySQL下载地址:https://dev.mysql.com/downloads/mysql/
可以直接在centos里面用wget命令下载,或者在自己电脑上下完再传上去
2.解压tar包
tar -xvf mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar
3.移除centos7自带的mariadb-libs包,不移除的话安装会出错;
yum remove -y mariadb-libs
4.使用yum localinstall命令进行本地安装,按照顺序执行
yum localinstall -y mysql-community-common-8.0.17-1.el7.x86_64.rpm
yum localinstall -y mysql-community-libs-8.0.17-1.el7.x86_64.rpm
yum localinstall -y mysql-community-client-8.0.17-1.el7.x86_64.rpm
yum localinstall -y mysql-community-server-8.0.17-1.el7.x86_64.rpm
yum localinstall -y mysql-community-libs-compat-8.0.17-1.el7.x86_64.rpm
期间yum会自动为我们安装所有的依赖包
5.启动mysql服务并允许开机自启
systemctl start mysqld
systemctl enable mysqld
6.查询mysql生成的临时的管理员账号密码(12位)
grep ‘temporary password‘ /var/log/mysql/mysqld.log
如果mysql.log文件在log目录下,使用:
grep ‘temporary password‘ /var/log/mysqld.log
7.使用生成的临时密码登录mysql
mysql -uroot -p
Enter password:
(输入上面的初始密码)
1)修改密码
alter user ‘root‘@‘localhost‘ identified by ‘新密码‘;
8.使用用如下命令开启远程服务。
CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘你的密码‘;
GRANT ALL ON *.* TO ‘root‘@‘%‘;
ALTER USER ‘root‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘你的密码‘;
三条命令按顺序执行完成后,刷新MySQL的系统权限相关表,否则会出现拒绝访问:
FLUSH PRIVILEGES;
exit
然后systemctl restart mysqld;
原文地址:https://www.cnblogs.com/xioawu-blog/p/11269603.html