1、先执行查询:
rpm -qa|grep mariadb
执行结果如:
mariadb-libs-5.5.64-1.el7.x86_64
2、先执行删除:
rpm -e --nodeps mariadb-libs
3、下载MySQL数据库:这里使用的是mysql-5.7.28版本
4、将下载好的MySQL安装包上传到服务器
5、到目录中解压文件:
tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
6、以下步骤非常重要请按步骤执行!!!!
a.rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
b.rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
c.rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
d.rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
如果是阿里云服务器执行“rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm ”会报错,不要慌,是缺少依赖:
sudo yum install libaio
再执行:rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
7、安装完成后,会生成几个文件,如下所示:
a、执行:
ls /etc/ | grep my 得到:
my.cnf
my.cnf.d
b、执行:
ls /var/lib/ | grep my 得到:
mysql
mysql-files
mysql-keyring
c、执行:
ls /var/log/ | grep my 得到:
mysqld.log
d、执行:
ls /var/run/ | grep my 得到:
mysqld
8、启动Mysql:
systemctl start mysqld.service
9、查看MySql运行状态如果看到:
systemctl status mysqld.service
绿色字体:active(running)就说明MySQL已经启动了
10、查看临时密码:
grep 'password' /var/log/mysqld.log
我这边儿显示的是:
2023-04-24T13:38:11.278973Z 1 [Note] A temporary password is generated for root@localhost: fpHETz,O2+S6
11、登录数据库:
mysql -u root -p
输入上边儿给出的密码:fpHETz,O2+S6(这个不一定,根据实际情况而定)
12、输入:
show databases;就会报错,原因:初始化密码已过期,查看数据库就会报错
报错内容:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
13、修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'WoShiDaYuanZhong_666';
14、退出验证密码:
quit;
再输入:mysql -u root -p
输入刚才设置的密码:WoShiDaYuanZhong_666
如果有显示内容 那么恭喜 Mysql已经安装完成了。
15、MySQL授权远程登录:
mysql> grant all privileges on *.* to 'root'@'%' identified by 'WoShiDaYuanZhong_666' with grant option;
注意:这是在MySQL用户下设置!!!!!!
16、开通MySQL默认端口3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
如果提示:FirewallD is not running,说明防火墙没有运行。需要开启防火墙再开启端口:
sudo systemctl start firewalld
再执行:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
注意:这个是在centos,root用户下!!!!!
17、MySQL设置开机自启动:
systemctl list-unit-files|grep mysqld.service
如果输出的值是:disable 就是:禁止开机自启动,一般情况下是 开机自启动的。
这样 MySQL 5. 7.28就安装完成了
参考文章:
https://blog.csdn.net/weixin_39515823/article/details/120212505
https://blog.csdn.net/weixin_45277608/article/details/127714913
标签:5.7,rpm,MySQL,28,centos7,64,mysql,安装 From: https://www.cnblogs.com/teninforxs/p/17362647.html