环境
Centos 7
Mysql5.7.28
下载Mysql
下载地址:https://downloads.mysql.com/archives/community/
你可以下载之后再上传到服务器。 如何架设FTP看这里:CENTOS 安装和简易配置VSFTP
或者直接wget我这里用的版本:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
#新建一个存放mysql文件的目录
mkdir /usr/local/mysql
cd /usr/local/mysql
#下载mysql
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
先删除 mariadb
rpm -qa | grep mariadb
#如果存在则会显示
mariadb-libs-5.5.65-1.el7.x86_64
#如果存在则删除,如果不存在则不用删除了
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
解压
tar -xvf mysql-5.7/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-test-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm
按照以下顺序安装
rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
如果出现
mysql-community-common(x86-64) >= 5.7.9 被 mysql-community-libs-5.7.28-1.el7.x86_64 需要
则在后面加入 --force --nodeps
在安装mysql-community-server-5.7.28-1.el7.x86_64.rpm 时可能会有libaio缺失
warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.28-1.el7.x86_64
那么安装一下libaio再继续安装mysql-community-server-5.7.28-1.el7.x86_64.rpm
yum install libaio
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
初始化一下mysql设置
vim /etc/my.cnf
#在[mysqld]组下添加
skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'
设置开机启动
#开机启动
systemctl enable mysqld.service
#启动mysql服务
systemctl start mysqld.service
给root用户设置一个密码
#输入mysql命令进入mysql命令行
msyql
#设置密码
update mysql.user set authentication_string=password('123456789') where user='root';
#刷新权限
flush privileges;
#退出命令行
exit
配置密码和权限
配置vim /etc/my.cnf,注释掉skip-grant-tables
[mysqld]
#skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'
重启mysql,并用刚才设置的密码登录
systemctl restart mysqld.service
mysql -u root -p
一般这个时候你执行其他sql会要求你重设一下密码才能继续,但是默认的密码验证是高强度,如果你想设置一个简单的密码,那么设置一下允许简单密码
set global validate_password_policy=LOW;
然后重设密码,两次密码可以一样
set password=password('123456789');
开启远程登录
设置一下防火墙
#放行3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#重启防火墙
firewall-cmd --reload
如果你要使用root进行远程登录,可以如下操作,如果不用则跳过这里直接添加其他远程账户登录
#允许root远程登录,远程登录密码可以和本地登录密码不一样,最好设置强壮一点
grant all privileges on *.* to 'root'@'%' identified by '远程登录密码' with grant option;
#刷新权限
flush privileges;
添加其他可以远程登录的账户
grant all privileges on *.* to '远程账户ID'@'%' identified by '远程登录密码' with grant option;
#刷新权限
flush privileges;
禁用一个账户的远程登录
delete from mysql.user where user="账户ID" and host<>"localhost";
#刷新权限
flush privileges;
完~