乐趣区

阿里云 centos7.6 安装 mysql8

创建 mysql 用户、用户组
groupadd mysql
useradd -g mysql mysql
passwd mysql
卸载系统自带的 mariadb
#查询
rpm -qa|grep mariadb
返回 mariadb-libs-5.5.60-1.el7_5.x86_64
#卸载
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64
返回
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
#强行卸载
rpm -e –nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

下载 mysql rpm
下载 mysql rpm 选择 Red Hat Enterprise Linux / Oracle LinuxRed Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)RPM Bundle 取得下载地址 https://cdn.mysql.com//Downlo…
wget “https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar”

tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

安装
安装依赖
yum install -y libaio.x86_64 libaio-devel.x86_64
yum install -y openssl-devel.x86_64 openssl.x86_64
yum install -y perl.x86_64 perl-devel.x86_64
yum install -y perl-JSON.noarch
yum install -y autoconf
必要安装,注意顺序,有依赖关系
rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
非必要安装,注意顺序,有依赖关系
rpm -ivh mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.13-1.el7.x86_64.rpm
初始化数据库
mysqld –initialize –console
修改目录权限
此步骤必须在初始化数据库之后!!!安装完默认是 mysql 用户、用户组的权限,如果没有,则更改
chown -R mysql:mysql /var/lib/mysql/
用 root 用户启动
systemctl start mysqld
若启动失败, 查看日志
tail -n 100 /var/log/mysqld.log
查看初始化时的密码
启动成功后可以查看初始化密码随机生成的
cat /var/log/mysqld.log | grep password
登录 MySQL 修改 mysql 用户密码
mysql -u root -p

# 修改密码
alter user ‘root’@’localhost’ identified by ‘yourpassword’;

# 远程设置
use mysql;
update user set host=’%’ where user=’root’;

# 授权用户名的权限,赋予任何主机访问数据的权限
grant all privileges ON *.* to ‘root’@’%’ with grant option;
flush privileges;
新增 mysql 用户, 创建数据库, 授权
create user ‘flame’@’%’ identified by ‘password’;
create database flame;
grant all privileges on flame.* to ‘flame’@’%’;
flush privileges;
centos7 防火墙开放端口
# 开放 3306 端口
firewall-cmd –zone=public –add-port=3306/tcp –permanent
#重载
firewall-cmd –reload
#查看状态
firewall-cmd –list-all
阿里云端口安全组设置
安全组说明新增 3306 端口的新增【入方向】规则
生产环境
mysql_secure_installation
会做以下操作

为 root 用户设置密码
删除匿名账号
取消 root 用户远程登录
删除 test 库和对 test 库的访问权限
刷新授权表使修改生效

相关管理命令
#启动 mysql
systemctl start mysqld.service
#结束
systemctl stop mysqld.service
#重启
systemctl restart mysqld.service
#开机自启
systemctl enable mysqld.service

退出移动版