1. 下载 rpm 程序包
下载 common libs client server 四个 rpm 程序包:
代码语言:shell复制mkdir ~/mysql-rpms
cd ~/mysql-rpms
curl -O -k https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-server-5.7.36-1.el7.x86_64.rpm
curl -O -k https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-client-5.7.36-1.el7.x86_64.rpm
curl -O -k https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-libs-5.7.36-1.el7.x86_64.rpm
curl -O -k https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/mysql-community-common-5.7.36-1.el7.x86_64.rpm
2. 安装依赖程序
先查询是否安装有mariadb:
代码语言:shell复制rpm -qa | grep mariadb
查询到的程序使用 rpm -e
卸载,以及用yum安装一些依赖程序
A. fedora
卸载冲突,安装依赖程序:
代码语言:shell复制sudo rpm -e --nodeps mariadb-connector-c
sudo rpm -e --nodeps mariadb-connector-c-config
sudo yum install libncurses*
B. centos
卸载冲突:
代码语言:shell复制sudo rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
C. 其它
其它情况下容器可能需要安装的依赖程序:
代码语言:shell复制sudo yum install libaio numactl-libs net-tools perl
3. 安装 mysql
一般情况下四个程序可以一起安装:
代码语言:shell复制sudo rpm -ivh *.rpm
如果安装失败就按顺序安装:
代码语言:shell复制sudo rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm
sudo rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm
4. 启动 mysqld
初始化 server 并查看临时密码:
代码语言:shell复制sudo mysqld --initialize --console
sudo cat /var/log/mysqld.log
启动 mysql server
代码语言:shell复制sudo chown -R mysql:mysql /var/lib/mysql
sudo systemctl start mysqld
5. 连接 mysql
使用初始化过程中的临时密码连接:
代码语言:shell复制mysql -u root -p
# 粘上密码按回车
修改临时密码:
代码语言:sql复制ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
如果提示太简单的密码改不上的话修改策略为低:
代码语言:sql复制-- SHOW VARIABLES LIKE 'validate_password%';
SET GLOBAL validate_password.policy=LOW;
然后再试 alter user
语句修改密码
退出程序:
代码语言:sql复制quit