后端砖头

MariaDB 安装部署、权限设置、外网访问

2023-03-05  本文已影响0人  王忘杰

本文使用Alma linux 8安装

一、安装数据库

配置mariabd源 /etc/yum.repos.d/MariaDB.repo

#MariaDB10.6CentOS repository list - created2023-02-02 03:14 UTC#https://mariadb.org/download/[mariadb]

name = MariaDB

baseurl = https://mirrors.aliyun.com/mariadb/yum/10.6/centos8-amd64

module_hotfixes=1

gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=1

二、安装数据库、启动、并设置开机启动

dnf clean all

dnf install mariadb-server

systemctl enable --now mariadb

三、进行MariaDB数据库初始化

mariadb-secure-installation

首先是设置密码,会提示先输入密码

Enter current password for root (enter for none):<–初次运行直接回车

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车

New password: <– 设置root用户的密码

Re-enter new password: <– 再输入一次你设置的密码

Remove anonymous users? [Y/n] <– 是否删除匿名用户

Disallow root login remotely? [Y/n] <–是否禁止root远程登录,建议禁止

Remove test database and access to it? [Y/n] <– 是否删除test数据库

Reload privilege tables now? [Y/n] <– 是否重新加载权限表

四、创建数据库和数据库管理员账号、只读账号,允许外网访问

control数据库管理员admin密码adminpasswd

control数据库只读guest密码guestpasswd

mysql -uroot -p登录

mariadb> create database control character set utf8mb4 collate utf8mb4_bin;

mariadb> create user admin@'%' identified by 'adminpasswd';

mariadb> grant all privileges on control.* to admin@'%';

mariadb> CREATE USER 'guest'@'%' IDENTIFIED BY 'guestpasswd';

mariadb> GRANT SELECT ON control.* TO 'guest'@'%';

mariadb> FLUSH PRIVILEGES;

mariadb> quit;

五、防火墙别忘了开放端口

firewall-cmd --add-port=3306/tcp --permanent

firewall-cmd --reload

firewall-cmd --list-ports

firewall-cmd --list-services

六、客户端连接测试

完毕

上一篇 下一篇

猜你喜欢

热点阅读