一.下载mysql
https://dev.mysql.com/downloads/mysql/
二.上传到服务器,解压
tar -xvf mysql-8.0.35-1.el7.x86_64.rpm-bundle.tar
三.安装
mariadb的lib包和mysql的lib包冲突,删掉
rpm -qa | grep mariadb | xargs rpm -e --nodeps
安装mysql服务
rpm -ivh mysql-community-common-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.35-1.el7.x86_64.rpm
四.初始化数据库
如果需要忽略表名大小写区分,在配置文件中加入以下内容,
配置文件位置:/etc/my.cnf
[mysqld]
lower-case-table-names=1
默认的安装目录:/var/lib/mysql
初始化
mysqld --initialize --user=mysql --datadir=/home/mysql/mysql-data
五.启动服务
systemctl start mysqld
六.设置用户
用root用户连接服务,初始化密码如下
grep 'temporary password' /var/log/mysqld.log
修改密码
ALTER USER root@localhost IDENTIFIED BY '123456';
设置远程可连接访问
use mysql;
update user set host = '%' where user = 'root';
flush privileges;