部署说明
Linux
上安装软件常见的几种方式:
- 源码编译
- 压缩包解压(一般为
tar.gz
) - 编译好的安装包(
RPM
、DPKG
等) - 在线安装(
YUM
、APT
等)
部署方式简单程度:
YUM
>RPM
>tar.gz
> 源码,本文介绍RPM
方式.
部署步骤
- 删除旧包
# 查找
rpm -qa | grep -i mysql
# 删除
rpm -ev mysql-libs-* --nodeps
下载
RPM
包mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar由于国外资源下载缓慢,可以使用华为开源镜像
解压压缩包
[root@mysql03 ~]# tar -xvf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-5.7.31-1.el7.x86_64.rpm
mysql-community-client-5.7.31-1.el7.x86_64.rpm
mysql-community-server-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-common-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-test-5.7.31-1.el7.x86_64.rpm
- 安装
只需要安装以下四个
mysql-community-libs-5.7.31-1.el7.x86_64.rpm
mysql-community-client-5.7.31-1.el7.x86_64.rpm
mysql-community-server-5.7.31-1.el7.x86_64.rpm
mysql-community-common-5.7.31-1.el7.x86_64.rpm
四个包有依赖关系。安装有先后顺序要求。
shell> rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
shell> rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm
shell> rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
shell> rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm
更简单的安装命令
# 这样,包之间会自动处理依赖和先后顺序
yum install mysql-community-{server,client,common,libs}-*
注意上面命令要求在解压后的目录里执行,不然
yum
找不到包就会到公网下载,速度非常慢.
- 启动服务
service mysqld start
service mysqld stop
service mysqld status
- 登录修改默认密码
# 获取root用户临时密码
cat /var/log/mysqld.log | more
# mysqld.log 临时密码
2020-07-28T01:23:53.588166Z 1 [Note] A temporary password is generated for root@localhost: dDO>*a4!uA+o
# 登录, 使用初始化生成的临时密码登录
mysql -u root -p
# 修改密码
set password for root@localhost = password('123456');
# 开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
修改密码时会报错
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
,意思是密码强度不符合要求.
可以修改/etc/my.cnf
, 添加validate_password=OFF
, 关闭密码强度校验, 然后重启service mysqld restart
.
mysql
安装RPM
方式比tar.gz
方式简单不少.