1.到官网下载免安装包
https://downloads.mysql.com/archives/community/
2.选择对应版本(mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz)带有glibc字样的是免安装的
3.新建存放数据的目录(可以自定义)
mkdir /data/mysql
4.修改目录权限
chown -R mysql:mysql /data/mysql/
5.把下载的安装包上传解压
6.mv将解压后的目录移动并重命名到/usr/local/mysql (路径可以自定义)
7.到/etc下新建my.cnf配置文件
8.将下面的配置拷贝进去
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
9.初始化数据库(下面三个路径都改成自己的)
/usr/local/mysql/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/u01/data/mysql
10.启动服务
service mysql start
11.跳过密码验证,在my.cnf最后添加如下配置
skip-grant-tables
12.重启mysql
13.登录mysql修改用户密码
set password for root@localhost = password('admin@2021');
14.允许远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION
15.如果报错就先执行flush privileges刷新一下权限,再重置密码
16.退出修改my.cnf,去掉skip-grant-tables这条配置 重新登录验证