一 前期准备
1.1 下载MySql5.7安装包
地址:https://dev.mysql.com/downloads/mysql/5.7.html
1.2 卸载 mariadb
Centos7 自带 mariadb ,在安装可能会有冲突,最好卸载掉 mariadb。
查看 mariadb
rpm -qa | grep mariadb
卸载 mariadb
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64
在命令最后添加参数说明:
--force强制安装
--nodeps就是安装时不检查依赖关系
二 安装单机版MySql
2.1 上传、解压
在/usr/local目录下创建mysql目录,将下载的安装包上传到该目录下
2.2 安装
rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm
2.3 初始化和配置
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld.service
systemctl enable mysqld
2.4 查询数据库默认密码
cat /var/log/mysqld.log | grep password
2.5 登录
# 密码是上一步输出的密码
mysql -uroot -pOS/imnkjk
2.6 修改密码
alter user 'root'@'localhost' identified with mysql_native_password by 'root';
2.7 远程访问授权
create user 'root'@'%' identified with mysql_native_password by 'root';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
2.8 修改my.cnf配置文件
2.9 常用命令
# 启动
systemctl start mysqld.service
# 停止
systemctl stop mysqld.service
# 查询状态
systemctl status mysqld.service
# 重启
service mysqld restart
2.10 开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --remove-port=3306/tcp --permanent
firewall-cmd --reload