centos8安装与配置Mysql,MongoDB

centos8安装与配置Mysql,MongoDB

centos8安装与配置Mysql,MongoDB

1.安装Mysql

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

导入DPG公钥 否贼无法通过DPG check

img

2.安装mysql服务

yum -y install mysql-community-server

img

3.开启mysql服务

systemctl start mysqld

4.设置mysql服务自启

systemctl enable mysqld

img

5.查看初始密码

grep "password" /var/log/mysqld.log

img

6.登陆并修改密码

mysql -uroot -p

alter user 'root'@'localhost' identified by 'xxxx';

7.创建新用户

create user 'abmcar'@'%' identified by 'xxx';

8.给新用户权限

grant all privileges on *.* to 'abmcar'@'%';

img

image-20220924111228810

2.安装和配置MongoDB

1.修改yum源

vim /etc/yum.repos.d/mongodb-org-5.0.repo

修改为

[mongodb-org-5.0]

name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc

2.yum安装

 yum install -y mongodb-org

img

3.开启服务

systemctl start mongod

4.设置开机自启

systemctl enable mongod

img

5.进入MongoDB

mongo

image-20220924105347786

6.选择数据库,创建用户,管理权限

use testdb
db.createUser({ user:"abmcar", pwd:"xxx",  roles:["readWrite", "dbAdmin"] })

7.修改mongodb.conf文件,启用身份验证,开始外部登录

vi /etc/mongod.conf

net:
  port: 27017
  #关键就在这里,否则默认127.0.0.1就只能内部连接
  bindIp: 0.0.0.0 

security:
  authorization: "enabled"   # disable or enabled

image-20220924110754221

Licensed under CC BY-NC-SA 4.0