1.首先通过 find / -name mysql 找到之前残余的mysql,通过 rm -rf 删除干净
2.通过wget下载
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
3.解压到 /usr/local 目录下
4.重命名为mysql
mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql
5.添加系统mysql组和mysql用户
groupadd mysql
useradd -r -g mysql mysql #useradd -r参数表示mysql用户是系统用户,不可用于登录系统
6.在mysql目录创建data目录
mkdir data
7.将所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql
8.在/usr/local/mysql/support-files目录下创建my_default.cnf
vim my_default.cnf
[mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 socket = /tmp/mysql.sock character-set-server=utf8 log-error = /usr/local/mysql/data/mysqld.log pid-file = /usr/local/mysql/data/mysqld.pid
9.拷贝
cp my_default.cnf /etc/my.cnf
10.在bin目录下初始化mysqld
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
11.初始化完成之后,查看日志
/usr/local/mysql/data/mysqld.log
12.可以看到临时密码
2021-04-08T06:14:29.790033Z 1 [Note] A temporary password is generated for root@localhost: a8?DQir=T+k+
13.把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
14.启动mysql服务
service mysql start
15.登录mysql,bin目录下
./mysql -u root -p
16.修改密码
set password=password('root');
8.0版本:
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'
17.授权
grant all privileges on *.* to root@'%' identified by 'root';
18.刷新权限
flush privileges;
19. 重新启动
service mysql restart