1、首先我们要优化我们的服务器Linux系统
iptables -F systemctl stop NetworkManager &> /dev/null systemctl disable NetworkManager &> /dev/null sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config &> /dev/null setenforce 0 systemctl stop firewalld systemctl disable firewalld
2、上传我们准备好的MySQL5.7安装包
tar xvf mysql5.7.tar.gz
cd mysql/
3、安装
我们在安装MySQL5.7前先要检测一下系统中有没有MariaDb数据库,可以试试卸载
yum remove mariadb -y
rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.24-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm
以上的rpm安装顺序不能颠倒,按照我这样最好
4、初始化数据库
我们在初始化数据库前可以对MySQL的速度优化,用下面的命令
echo skip-name-resolve >> /etc/my.cnf
systemctl start mysqld #启动数据库服务 systemctl status mysqld #查看数据库服务的状态 systemctl enable mysqld #将数据库服务加入开机自启
cat /var/log/mysqld.log | grep "password" #获取MySQL的随机默认密码
mysql -uroot -p'f!&Ks+wr?5?k' #登录MySQL数据库
5、进入数据库后我们需要更改密码,否则无法操作数据库
ALTER USER 'root'@'localhost' identified by "12345678"; #我们将密码改为12345678
我们发现密码设置为12345678会报错
MySQL5.7密码需要大小写英语字母加特殊符号
flush privileges; #刷新权限,立即生效