登录
首页 >  数据库 >  MySQL

阿里云 centos7.6 安装 mysql8

来源:SegmentFault

时间:2023-02-24 18:17:30 194浏览 收藏

哈喽!今天心血来潮给大家带来了《阿里云 centos7.6 安装 mysql8》,想必大家应该对数据库都不陌生吧,那么阅读本文就都不会很困难,以下内容主要涉及到MySQL、Linux、centos,若是你正在学习数据库,千万别错过这篇文章~希望能帮助到你!

创建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 Linux
Red 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

初始化数据库

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
systemctl start mysqld.service
#结束
systemctl stop mysqld.service
#重启
systemctl restart mysqld.service
#开机自启
systemctl enable mysqld.service

本篇关于《阿里云 centos7.6 安装 mysql8》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于数据库的相关知识,请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>