第一种使用yum或者dnf的方式安装
1.在centos里配置一个本地仓库
[root@localhost ~]# mount /dev/sr0 /etc/cdrom/
mount: /etc/cdrom: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# cat /etc/yum.repos.d/gg.repo
[baseos]
name=BaseOS
baseurl=file:///etc/cdrom/BaseOS
gpgcheck=0
enabled=1
[appsteam]
name=appstream
baseurl=file:///etc/cdrom/AppStream
gpgcheck=0
enabled=1
[root@localhost ~]#
[root@localhost ~]# yum -y install vim /测试一下本地仓库是否配置成功
上次元数据过期检查:1 day, 0:01:30 前,执行于 2023年03月01日 星期三 00时40分15秒。
软件包 vim-enhanced-2:8.0.1763-15.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@localhost ~]#
2.搜索mariadb软件,并安装
[root@localhost ~]# yum search mariadb
上次元数据过期检查:1 day, 0:00:29 前,执行于 2023年03月01日 星期三 00时40分15秒。
============================ 名称 精准匹配:mariadb ============================
mariadb.x86_64 : A very fast and robust SQL database server
========================== 名称 和 概况 匹配:mariadb ==========================
mariadb-connector-c.i686 : The MariaDB Native Client library (C driver)
mariadb-connector-c.x86_64 : The MariaDB Native Client library (C driver)
mariadb-connector-c-devel.i686 : Development files for mariadb-connector-c
mariadb-connector-c-devel.x86_64 : Development files for mariadb-connector-c
mariadb-connector-odbc.x86_64 : The MariaDB Native Client library (ODBC driver)
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-embedded.x86_64 : MariaDB as an embeddable library
mariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable
: library
mariadb-java-client.noarch : Connects applications developed in Java to MariaDB
: and MySQL databases
mariadb-oqgraph-engine.x86_64 : The Open Query GRAPH engine for MariaDB
mariadb-server.x86_64 : The MariaDB server and related files
mariadb-server-utils.x86_64 : Non-essential server utilities for MariaDB/MySQL
: applications
mariadb-test.x86_64 : The test suite distributed with MariaDB
============================== 名称 匹配:mariadb ==============================
mariadb-backup.x86_64 : The mariabackup tool for physical online backups
mariadb-common.x86_64 : The shared files required by server and client
mariadb-connector-c-config.noarch : Configuration files for packages that use
: /etc/my.cnf as a configuration file
mariadb-errmsg.x86_64 : The error messages files required by server and embedded
mariadb-gssapi-server.x86_64 : GSSAPI authentication plugin for server
mariadb-server-galera.x86_64 : The configuration files and scripts for galera
: replication
[root@localhost ~]# yum -y install mariadb* /安装数据库
上次元数据过期检查:1 day, 0:04:58 前,执行于 2023年03月01日 星期三 00时40分15秒。
依赖关系解决。
=============================================================================================================================================================================================
软件包 架构 版本 仓库 大小
=============================================================================================================================================================================================
安装:
----------------------------------------------------略
已安装:
Judy-1.0.5-18.module_el8.1.0+217+4d875839.x86_64 copy-jdk-configs-3.7-4.el8.noarch
galera-25.3.26-1.module_el8.1.0+217+4d875839.x86_64 java-1.8.0-openjdk-headless-1:1.8.0.272.b10-4.el8.x86_64
javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch keyutils-libs-devel-1.5.10-6.el8.x86_64
krb5-devel-1.18.2-7.el8.x86_64 libaio-devel-0.3.112-1.el8.x86_64
libcom_err-devel-1.45.6-1.el8.x86_64 libkadm5-1.18.2-7.el8.x86_64
libselinux-devel-2.9-5.el8.x86_64 libsepol-devel-2.9-1.el8.x86_64
libverto-devel-0.3.0-5.el8.x86_64 lksctp-tools-1.0.18-3.el8.x86_64
mariadb-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-backup-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-common-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-connector-c-3.0.7-1.el8.x86_64
mariadb-connector-c-config-3.0.7-1.el8.noarch mariadb-connector-c-devel-3.0.7-1.el8.x86_64
mariadb-connector-odbc-3.0.7-1.el8.x86_64 mariadb-devel-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-embedded-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-embedded-devel-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-errmsg-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-gssapi-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-java-client-2.2.5-3.el8.noarch mariadb-oqgraph-engine-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-server-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-server-galera-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
mariadb-server-utils-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 mariadb-test-3:10.3.17-1.module_el8.1.0+257+48736ea6.x86_64
openssl-devel-1:1.1.1g-11.el8.x86_64 pcre2-devel-10.32-2.el8.x86_64
pcre2-utf16-10.32-2.el8.x86_64 pcre2-utf32-10.32-2.el8.x86_64
perl-DBD-MySQL-4.046-3.module_el8.3.0+419+c2dec72b.x86_64 perl-Env-1.04-395.el8.noarch
perl-Memoize-1.03-416.el8.noarch perl-Test-Simple-1:1.302135-1.el8.noarch
perl-Time-HiRes-4:1.9758-2.el8.x86_64 tzdata-java-2020d-1.el8.noarch
unixODBC-2.3.7-1.el8.x86_64 zlib-devel-1.2.11-17.el8.x86_64
完毕!
[root@localhost ~]#
3.重启mariadb服务
[root@localhost ~]# systemctl restart mariadb.service
[root@localhost ~]# systemctl enable mariadb.service
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]#
4.初始化数据库
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password: /设置密码 此处的密码自己设置
Re-enter new password: /确认密码
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@localhost ~]#
5.登录数据库
[root@localhost ~]# mysql -uroot -p123 /-u指定登录的账户 -p输入密码
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>