@Linux下MySQL8.0搭建
1.卸载mariadb
rpm -qa |grep mariadb //检查是否有安装mariadb,centos默认安装此数据库
rpm -e mariadb-libs-5.5.65-1.el7.x86_64 --nodeps //卸载mariadb
rpm -qa |grep mariadb
2.开始安装
官网下载mysql,根据需求选择需要的版本
https://dev.mysql.com/downloads/mysql/
tar -xvf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
按如下顺序安装,存在依赖关系
安装common
rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm --nodeps --force 命令安装 common
安装libs
rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm --nodeps --force
安装client
rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm --nodeps --force
安装Server
rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm --nodeps --force
3.检查
rpm -qa |grep mysql
4.mysql初始化
mysqld --initialize-insecure; //mysql初始化为无密码登录
chown mysql:mysql /var/lib/mysql -R; //更改属组
systemctl start mysqld.service; //启动mysql
systemctl enable mysqld; //开机自动启动
5.登录mysql
mysql -u root -p
修改密码
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘root’;
远程授权
create user ‘root’@’%’ identified with mysql_native_password by ‘root’;
grant all privileges on . to ‘root’@’%’ with grant option;
flush privileges;
6.关闭防火墙
systemctl stop firewalld.service;
systemctl disable firewalld.service;
systemctl mask firewalld.service;