Linux下Mariadb安装与配置

配置yum源

  • 这里我们使用的阿里云
[root@rhel9-node1 yum.repos.d]# cat redhat.repo
[app]
name=appstream
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/
gpgcheck=0

[base]
name=baseos
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/
gpgcheck=0

安装mariadb-server

[root@rhel9-node1 ~]# yum install mariadb-server -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:0:36:29 前,执行于 2024年08月03日 星期六 20时30分07秒。
依赖关系解决。
==================================================================================================
 软件包                              架构            版本                      仓库          大小
==================================================================================================
安装:
 mariadb-server                      x86_64          3:10.5.22-1.el9           app          9.7 M
安装依赖关系:
 mariadb                             x86_64          3:10.5.22-1.el9           app          1.6 M
 mariadb-common                      x86_64          3:10.5.22-1.el9           app           31 k
 mariadb-connector-c                 x86_64          3.2.6-1.el9               app          198 k
 mariadb-connector-c-config          noarch          3.2.6-1.el9               app           11 k
 mariadb-errmsg                      x86_64          3:10.5.22-1.el9           app          220 k
 mysql-selinux                       noarch          1.0.5-1.el9               app           36 k
 perl-DBD-MariaDB                    x86_64          1.21-16.el9               app          152 k
 perl-File-Copy                      noarch          2.34-481.el9              app           20 k
 perl-Sys-Hostname                   x86_64          1.23-481.el9              app           17 k
安装弱的依赖:
 mariadb-backup                      x86_64          3:10.5.22-1.el9           app          6.5 M
 mariadb-gssapi-server               x86_64          3:10.5.22-1.el9           app           16 k
 mariadb-server-utils                x86_64          3:10.5.22-1.el9           app          215 k

事务概要
==================================================================================================
安装  13 软件包

总下载:19 M
安装大小:109 M
下载软件包:
(1/13): mariadb-common-10.5.22-1.el9.x86_64.rpm                    54 kB/s |  31 kB     00:00
(2/13): mariadb-connector-c-3.2.6-1.el9.x86_64.rpm                613 kB/s | 198 kB     00:00
(3/13): mariadb-connector-c-config-3.2.6-1.el9.noarch.rpm         186 kB/s |  11 kB     00:00
(4/13): mariadb-errmsg-10.5.22-1.el9.x86_64.rpm                   1.9 MB/s | 220 kB     00:00
(5/13): mariadb-10.5.22-1.el9.x86_64.rpm                          1.4 MB/s | 1.6 MB     00:01
(6/13): mariadb-gssapi-server-10.5.22-1.el9.x86_64.rpm            453 kB/s |  16 kB     00:00
(7/13): mariadb-server-utils-10.5.22-1.el9.x86_64.rpm             1.5 MB/s | 215 kB     00:00
(8/13): mysql-selinux-1.0.5-1.el9.noarch.rpm                      494 kB/s |  36 kB     00:00
(9/13): perl-DBD-MariaDB-1.21-16.el9.x86_64.rpm                   251 kB/s | 152 kB     00:00
(10/13): perl-File-Copy-2.34-481.el9.noarch.rpm                    52 kB/s |  20 kB     00:00
(11/13): perl-Sys-Hostname-1.23-481.el9.x86_64.rpm                 33 kB/s |  17 kB     00:00
(12/13): mariadb-backup-10.5.22-1.el9.x86_64.rpm                  1.5 MB/s | 6.5 MB     00:04
(13/13): mariadb-server-10.5.22-1.el9.x86_64.rpm                  1.6 MB/s | 9.7 MB     00:05
--------------------------------------------------------------------------------------------------
总计                                                              2.6 MB/s |  19 MB     00:07
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                   1/1
  安装    : mariadb-connector-c-config-3.2.6-1.el9.noarch                                    1/13
  安装    : mariadb-common-3:10.5.22-1.el9.x86_64                                            2/13
  安装    : mariadb-connector-c-3.2.6-1.el9.x86_64                                           3/13
  安装    : perl-Sys-Hostname-1.23-481.el9.x86_64                                            4/13
  安装    : perl-DBD-MariaDB-1.21-16.el9.x86_64                                              5/13
  安装    : mariadb-errmsg-3:10.5.22-1.el9.x86_64                                            6/13
  安装    : perl-File-Copy-2.34-481.el9.noarch                                               7/13
  运行脚本: mysql-selinux-1.0.5-1.el9.noarch                                                 8/13
  安装    : mysql-selinux-1.0.5-1.el9.noarch                                                 8/13
  运行脚本: mysql-selinux-1.0.5-1.el9.noarch                                                 8/13
libsemanage.semanage_direct_install_info: Overriding mysql module at lower priority 100 with module at priority 200.

  安装    : mariadb-backup-3:10.5.22-1.el9.x86_64                                            9/13
  安装    : mariadb-gssapi-server-3:10.5.22-1.el9.x86_64                                    10/13
  安装    : mariadb-server-utils-3:10.5.22-1.el9.x86_64                                     11/13
  运行脚本: mariadb-server-3:10.5.22-1.el9.x86_64                                           12/13
  安装    : mariadb-server-3:10.5.22-1.el9.x86_64                                           12/13
  运行脚本: mariadb-server-3:10.5.22-1.el9.x86_64                                           12/13
  安装    : mariadb-3:10.5.22-1.el9.x86_64                                                  13/13
  运行脚本: mysql-selinux-1.0.5-1.el9.noarch                                                13/13
  运行脚本: mariadb-3:10.5.22-1.el9.x86_64                                                  13/13
  验证    : mariadb-3:10.5.22-1.el9.x86_64                                                   1/13
  验证    : mariadb-backup-3:10.5.22-1.el9.x86_64                                            2/13
  验证    : mariadb-common-3:10.5.22-1.el9.x86_64                                            3/13
  验证    : mariadb-connector-c-3.2.6-1.el9.x86_64                                           4/13
  验证    : mariadb-connector-c-config-3.2.6-1.el9.noarch                                    5/13
  验证    : mariadb-errmsg-3:10.5.22-1.el9.x86_64                                            6/13
  验证    : mariadb-gssapi-server-3:10.5.22-1.el9.x86_64                                     7/13
  验证    : mariadb-server-3:10.5.22-1.el9.x86_64                                            8/13
  验证    : mariadb-server-utils-3:10.5.22-1.el9.x86_64                                      9/13
  验证    : mysql-selinux-1.0.5-1.el9.noarch                                                10/13
  验证    : perl-DBD-MariaDB-1.21-16.el9.x86_64                                             11/13
  验证    : perl-File-Copy-2.34-481.el9.noarch                                              12/13
  验证    : perl-Sys-Hostname-1.23-481.el9.x86_64                                           13/13
已更新安装的产品。

已安装:
  mariadb-3:10.5.22-1.el9.x86_64                      mariadb-backup-3:10.5.22-1.el9.x86_64
  mariadb-common-3:10.5.22-1.el9.x86_64               mariadb-connector-c-3.2.6-1.el9.x86_64
  mariadb-connector-c-config-3.2.6-1.el9.noarch       mariadb-errmsg-3:10.5.22-1.el9.x86_64
  mariadb-gssapi-server-3:10.5.22-1.el9.x86_64        mariadb-server-3:10.5.22-1.el9.x86_64
  mariadb-server-utils-3:10.5.22-1.el9.x86_64         mysql-selinux-1.0.5-1.el9.noarch
  perl-DBD-MariaDB-1.21-16.el9.x86_64                 perl-File-Copy-2.34-481.el9.noarch
  perl-Sys-Hostname-1.23-481.el9.x86_64

完毕!
[root@rhel9-node1 ~]#

启动mariadb

[root@rhel9-node1 ~]# systemctl start mariadb
[root@rhel9-node1 ~]# systemctl is-active mariadb
active

mariadb数据库初始化

[root@rhel9-node1 ~]# 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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):     #输入当前数据库密码,没有就直接回车
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n     #是否使用socket访问
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y    设置root用户密码
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     #是否禁止root用户远程登录
 ... 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密码还是不会生效的,需要登录到数据库中进行修改
[root@rhel9-node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.5.22-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)]> alter user root@localhost identified by "huazi";
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit
Bye
[root@rhel9-node1 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@rhel9-node1 ~]# mysql -uroot -phuazi
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.5.22-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| huazi              |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.002 sec)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

^~^前行者~~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值