56 openEuler搭建Mariadb数据库服务器-安装、运行和卸载

56 openEuler搭建Mariadb数据库服务器-安装、运行和卸载56.1 安装56.2 运行56.3 卸载

56 openEuler搭建Mariadb数据库服务器-安装、运行和卸载

56.1 安装

  1. 配置本地yum源,详细信息请参考《openEuler 22.03-LTS 搭建repo服务器》。

  2. 清除缓存。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n9" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># dnf clean all</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n11" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# dnf clean all
    45 files removed
    [root@superman-21 ~]# </pre>

  3. 创建缓存。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n14" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># dnf makecache</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n16" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# dnf makecache
    OS 6.5 MB/s | 3.4 MB 00:00
    everything 18 MB/s | 16 MB 00:00
    EPOL 5.4 MB/s | 2.6 MB 00:00
    debuginfo 3.2 MB/s | 3.9 MB 00:01
    source 3.9 MB/s | 1.7 MB 00:00
    update 15 MB/s | 29 MB 00:01
    Metadata cache created.
    [root@superman-21 ~]# </pre>

  4. 在root权限下安装mariadb服务器。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n19" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># dnf install mariadb-server</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n21" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# dnf install mariadb-server
    Last metadata expiration check: 0:01:18 ago on 2022年12月19日 星期一 21时18分58秒.
    Dependencies resolved.
    =============================================================================================================================
    Package Architecture Version Repository Size
    =============================================================================================================================
    Installing:
    mariadb-server x86_64 4:10.5.16-1.oe2203 update 18 M
    Installing dependencies:
    mariadb x86_64 4:10.5.16-1.oe2203 update 6.0 M
    mariadb-common x86_64 4:10.5.16-1.oe2203 update 27 k
    mariadb-config x86_64 4:10.5.16-1.oe2203 update 8.0 k
    mariadb-errmsg x86_64 4:10.5.16-1.oe2203 update 231 k
    mysql-selinux noarch 1.0.0-2.oe2203 everything 35 k
    perl-DBD-MariaDB x86_64 1.21-3.oe2203 OS 122 k
    perl-DBI x86_64 1.643-3.oe2203 update 462 k
    Installing weak dependencies:
    mariadb-backup x86_64 4:10.5.16-1.oe2203 update 6.6 M
    mariadb-gssapi-server x86_64 4:10.5.16-1.oe2203 update 14 k
    mariadb-server-utils x86_64 4:10.5.16-1.oe2203 update 1.1 M

    Transaction Summary

    Install 11 Packages

    Total download size: 32 M
    Installed size: 168 M
    Is this ok [y/N]: y
    Downloading Packages:
    (1/11): mysql-selinux-1.0.0-2.oe2203.noarch.rpm 286 kB/s | 35 kB 00:00
    (2/11): perl-DBD-MariaDB-1.21-3.oe2203.x86_64.rpm 617 kB/s | 122 kB 00:00
    (3/11): mariadb-common-10.5.16-1.oe2203.x86_64.rpm 648 kB/s | 27 kB 00:00
    (4/11): mariadb-config-10.5.16-1.oe2203.x86_64.rpm 205 kB/s | 8.0 kB 00:00
    (5/11): mariadb-errmsg-10.5.16-1.oe2203.x86_64.rpm 2.7 MB/s | 231 kB 00:00
    (6/11): mariadb-gssapi-server-10.5.16-1.oe2203.x86_64.rpm 328 kB/s | 14 kB 00:00
    (7/11): mariadb-server-10.5.16-1.oe2203.x86_64.rpm 15 MB/s | 18 MB 00:01
    (8/11): mariadb-server-utils-10.5.16-1.oe2203.x86_64.rpm 4.4 MB/s | 1.1 MB 00:00
    (9/11): perl-DBI-1.643-3.oe2203.x86_64.rpm 8.9 MB/s | 462 kB 00:00
    (10/11): mariadb-backup-10.5.16-1.oe2203.x86_64.rpm 2.9 MB/s | 6.6 MB 00:02
    (11/11): mariadb-10.5.16-1.oe2203.x86_64.rpm 2.3 MB/s | 6.0 MB 00:02


    Total 12 MB/s | 32 MB 00:02
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
    Preparing : 1/1
    Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 1/11
    Installing : perl-DBI-1.643-3.oe2203.x86_64 1/11
    Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 1/11
    Installing : mariadb-config-4:10.5.16-1.oe2203.x86_64 2/11
    Installing : mariadb-common-4:10.5.16-1.oe2203.x86_64 3/11
    Installing : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 4/11
    Installing : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 5/11
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 6/11
    Installing : mysql-selinux-1.0.0-2.oe2203.noarch 6/11
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 6/11
    libsemanage.semanage_direct_install_info: Overriding mysql module at lower priority 100 with module at priority 200.

    Installing : mariadb-4:10.5.16-1.oe2203.x86_64 7/11
    Installing : mariadb-backup-4:10.5.16-1.oe2203.x86_64 8/11
    Installing : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 9/11
    Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 10/11
    Installing : mariadb-server-4:10.5.16-1.oe2203.x86_64 10/11
    Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 10/11
    Installing : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 11/11
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 11/11
    Running scriptlet: mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 11/11
    /usr/lib/tmpfiles.d/pesign.conf:1: Line references path below legacy directory /var/run/, updating /var/run/pesign → /run/pesign; please update the tmpfiles.d/ drop-in file accordingly.

    Verifying : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 1/11
    Verifying : mysql-selinux-1.0.0-2.oe2203.noarch 2/11
    Verifying : mariadb-4:10.5.16-1.oe2203.x86_64 3/11
    Verifying : mariadb-backup-4:10.5.16-1.oe2203.x86_64 4/11
    Verifying : mariadb-common-4:10.5.16-1.oe2203.x86_64 5/11
    Verifying : mariadb-config-4:10.5.16-1.oe2203.x86_64 6/11
    Verifying : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 7/11
    Verifying : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 8/11
    Verifying : mariadb-server-4:10.5.16-1.oe2203.x86_64 9/11
    Verifying : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 10/11
    Verifying : perl-DBI-1.643-3.oe2203.x86_64 11/11

    Installed:
    mariadb-4:10.5.16-1.oe2203.x86_64 mariadb-backup-4:10.5.16-1.oe2203.x86_64
    mariadb-common-4:10.5.16-1.oe2203.x86_64 mariadb-config-4:10.5.16-1.oe2203.x86_64
    mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64
    mariadb-server-4:10.5.16-1.oe2203.x86_64 mariadb-server-utils-4:10.5.16-1.oe2203.x86_64
    mysql-selinux-1.0.0-2.oe2203.noarch perl-DBD-MariaDB-1.21-3.oe2203.x86_64
    perl-DBI-1.643-3.oe2203.x86_64

    Complete!
    [root@superman-21 ~]#</pre>

  5. 查看安装后的rpm包。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n24" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># rpm -qa | grep mariadb</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n26" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# rpm -qa | grep mariadb
    mariadb-errmsg-10.5.16-1.oe2203.x86_64
    mariadb-common-10.5.16-1.oe2203.x86_64
    mariadb-gssapi-server-10.5.16-1.oe2203.x86_64
    mariadb-server-utils-10.5.16-1.oe2203.x86_64
    mariadb-backup-10.5.16-1.oe2203.x86_64
    mariadb-10.5.16-1.oe2203.x86_64
    mariadb-server-10.5.16-1.oe2203.x86_64
    mariadb-config-10.5.16-1.oe2203.x86_64
    mariadb-connector-c-3.1.13-2.oe2203.x86_64
    [root@superman-21 ~]# </pre>

56.2 运行

  1. 设置mariadb数据库配置文件。

    /etc/my.cnf的[client-server]下添加socket,[mysqld]下添加datadir、log-error,pid-file、socket;

    /etc/my.cnf.d/mariadb-server.cnf的[mysqld]下添加datadir、log-error,pid-file、socket

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># vi /etc/my.cnf</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n35" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# cat /etc/my.cnf

    This group is read both both by the client and the server

    use it for options that affect everything

    [client-server]
    socket = /data/mariadb/tmp/mysql.sock

    This group is read by the server

    [mysqld]
    datadir = /data/mariadb/data
    log-error = /data/mariadb/log/mariadberr.log
    pid-file = /data/mariadb/run/mariadb.pid
    socket = /data/mariadb/tmp/mysql.sock

    Disabling symbolic-links is recommended to prevent assorted security risks

    symbolic-links=0

    include all files from the config directory

    !includedir /etc/my.cnf.d

    [root@superman-21 ~]#
    [root@superman-21 ~]# cat /etc/my.cnf.d/mariadb-server.cnf

    These groups are read by MariaDB server.

    Use it for options that only the server (but not clients) should see

    See the examples of server my.cnf files in /usr/share/mysql/

    this is read by the standalone daemon and embedded servers

    [server]

    this is only for the mysqld standalone daemon

    Settings user and group are ignored when systemd is used.

    If you need to run mysqld under a different user or group,

    customize your systemd unit file for mysqld/mariadb according to the

    instructions in http://fedoraproject.org/wiki/Systemd

    [mysqld]
    datadir = /data/mariadb/data
    log-error = /data/mariadb/log/mariadberr.log
    pid-file = /data/mariadb/run/mariadb.pid
    socket = /data/mariadb/tmp/mysql.sock

    * Galera-related settings

    [galera]

    Mandatory settings

    wsrep_on=ON

    wsrep_provider=

    wsrep_cluster_address=

    binlog_format=row

    default_storage_engine=InnoDB

    innodb_autoinc_lock_mode=2

    Allow server to accept connections on all interfaces.

    bind-address=0.0.0.0

    Optional setting

    wsrep_slave_threads=1

    innodb_flush_log_at_trx_commit=0

    this is only for embedded server

    [embedded]

    This group is only read by MariaDB servers, not by MySQL.

    If you use the same .cnf file for MySQL and MariaDB,

    you can put MariaDB-only options here

    [mariadb]

    This group is only read by MariaDB-10.5 servers.

    If you use the same .cnf file for MariaDB of different versions,

    use this group for options that older servers don't understand

    [mariadb-10.5]

    [root@superman-21 ~]# </pre>

  2. 在root权限下启动mariadb服务器。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n38" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># systemctl start mariadb</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n40" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# systemctl start mariadb.service
    [root@superman-21 ~]#
    [root@superman-21 ~]# ll /data/mariadb/data/
    总用量 122920
    -rw-rw---- 1 mysql mysql 24576 12月 20 17:03 aria_log.00000001
    -rw-rw---- 1 mysql mysql 52 12月 20 17:03 aria_log_control
    -rw-rw---- 1 mysql mysql 972 12月 20 17:03 ib_buffer_pool
    -rw-rw---- 1 mysql mysql 12582912 12月 20 17:03 ibdata1
    -rw-rw---- 1 mysql mysql 100663296 12月 20 17:03 ib_logfile0
    -rw-rw---- 1 mysql mysql 12582912 12月 20 17:03 ibtmp1
    -rw-rw---- 1 mysql mysql 0 12月 20 17:03 multi-master.info
    drwx------ 2 mysql mysql 4096 12月 20 17:03 mysql
    -rw-rw---- 1 mysql mysql 16 12月 20 17:03 mysql_upgrade_info
    drwx------ 2 mysql mysql 20 12月 20 17:03 performance_schema
    [root@superman-21 ~]#
    [root@superman-21 ~]# ll /data/mariadb/log/
    总用量 4
    -rw-rw---- 1 mysql mysql 1578 12月 20 17:03 mariadberr.log
    [root@superman-21 ~]#
    [root@superman-21 ~]# ll /data/mariadb/run/
    总用量 4
    -rw-rw---- 1 mysql mysql 5 12月 20 17:03 mariadb.pid
    [root@superman-21 ~]#
    [root@superman-21 ~]# ll /data/mariadb/tmp/
    总用量 0
    srwxrwxrwx 1 mysql mysql 0 12月 20 17:03 mysql.sock
    [root@superman-21 ~]# </pre>

  3. 设置socket软连接。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n43" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># ln -s /data/mariadb/tmp/mysql.sock /var/lib/mysql/mysql.sock</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n45" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# ln -s /data/mariadb/tmp/mysql.sock /var/lib/mysql/mysql.sock
    [root@superman-21 ~]# </pre>

  4. 在root权限下安全初始化数据库。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n48" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># /usr/bin/mysql_secure_installation</pre>

    命令执行过程中需要输入数据库的root设置的密码,若没有密码则直接按“Enter”。然后根据提示及实际情况进行设置。

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n51" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# /usr/bin/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
    ... skipping.

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

    Change the 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@superman-21 ~]#</pre>
  1. 登录数据库。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n54" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mysql -u root -p</pre>

    命令执行后提示输入密码。密码为4中设置的密码。

    [图片上传失败...(image-e0ca4e-1681904635376)]

    说明: 执行 \q 或者 exit 可退出数据库。

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n59" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# mysql -u root -p
    Enter password:
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 11
    Server version: 10.5.16-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)]>
    MariaDB [(none)]> \q
    Bye
    [root@superman-21 ~]#
    [root@superman-21 ~]# mysql -u root -p
    Enter password:
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 12
    Server version: 10.5.16-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)]> exit
    Bye
    [root@superman-21 ~]# </pre>

56.3 卸载

  1. 在root权限下关闭数据库进程。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n64" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># systemctl stop mariadb</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n66" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# systemctl stop mariadb
    [root@superman-21 ~]# </pre>

  2. 在root权限下执行dnf remove mariadb-server命令卸载mariadb。

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n69" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># dnf remove mariadb-server</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n71" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# dnf remove mariadb-server
    Dependencies resolved.
    =============================================================================================================================
    Package Architecture Version Repository Size
    =============================================================================================================================
    Removing:
    mariadb-server x86_64 4:10.5.16-1.oe2203 @update 91 M
    Removing unused dependencies:
    mariadb x86_64 4:10.5.16-1.oe2203 @update 38 M
    mariadb-backup x86_64 4:10.5.16-1.oe2203 @update 27 M
    mariadb-common x86_64 4:10.5.16-1.oe2203 @update 179 k
    mariadb-config x86_64 4:10.5.16-1.oe2203 @update 345
    mariadb-errmsg x86_64 4:10.5.16-1.oe2203 @update 2.6 M
    mariadb-gssapi-server x86_64 4:10.5.16-1.oe2203 @update 19 k
    mariadb-server-utils x86_64 4:10.5.16-1.oe2203 @update 7.3 M
    mysql-selinux noarch 1.0.0-2.oe2203 @everything 49 k
    perl-DBD-MariaDB x86_64 1.21-3.oe2203 @OS 356 k
    perl-DBI x86_64 1.643-3.oe2203 @update 1.6 M

    Transaction Summary

    Remove 11 Packages

    Freed space: 168 M
    Is this ok [y/N]: y
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
    Preparing : 1/1
    Running scriptlet: mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 1/1
    Erasing : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 1/11
    Erasing : mariadb-backup-4:10.5.16-1.oe2203.x86_64 2/11
    Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 3/11
    Erasing : mariadb-server-4:10.5.16-1.oe2203.x86_64 3/11
    警告:/etc/my.cnf.d/mariadb-server.cnf 已另存为 /etc/my.cnf.d/mariadb-server.cnf.rpmsave

    Running scriptlet: mariadb-server-4:10.5.16-1.oe2203.x86_64 3/11
    Erasing : mariadb-4:10.5.16-1.oe2203.x86_64 4/11
    Erasing : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 5/11
    Erasing : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 6/11
    Erasing : mariadb-common-4:10.5.16-1.oe2203.x86_64 7/11
    Erasing : mariadb-config-4:10.5.16-1.oe2203.x86_64 8/11
    警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave

    Erasing : mysql-selinux-1.0.0-2.oe2203.noarch 9/11
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 9/11
    libsemanage.semanage_direct_remove_key: mysql module at priority 100 is now active.

    Erasing : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 10/11
    Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 11/11
    Erasing : perl-DBI-1.643-3.oe2203.x86_64 11/11
    Running scriptlet: perl-DBI-1.643-3.oe2203.x86_64 11/11
    Verifying : mariadb-4:10.5.16-1.oe2203.x86_64 1/11
    Verifying : mariadb-backup-4:10.5.16-1.oe2203.x86_64 2/11
    Verifying : mariadb-common-4:10.5.16-1.oe2203.x86_64 3/11
    Verifying : mariadb-config-4:10.5.16-1.oe2203.x86_64 4/11
    Verifying : mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 5/11
    Verifying : mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64 6/11
    Verifying : mariadb-server-4:10.5.16-1.oe2203.x86_64 7/11
    Verifying : mariadb-server-utils-4:10.5.16-1.oe2203.x86_64 8/11
    Verifying : mysql-selinux-1.0.0-2.oe2203.noarch 9/11
    Verifying : perl-DBD-MariaDB-1.21-3.oe2203.x86_64 10/11
    Verifying : perl-DBI-1.643-3.oe2203.x86_64 11/11

    Removed:
    mariadb-4:10.5.16-1.oe2203.x86_64 mariadb-backup-4:10.5.16-1.oe2203.x86_64
    mariadb-common-4:10.5.16-1.oe2203.x86_64 mariadb-config-4:10.5.16-1.oe2203.x86_64
    mariadb-errmsg-4:10.5.16-1.oe2203.x86_64 mariadb-gssapi-server-4:10.5.16-1.oe2203.x86_64
    mariadb-server-4:10.5.16-1.oe2203.x86_64 mariadb-server-utils-4:10.5.16-1.oe2203.x86_64
    mysql-selinux-1.0.0-2.oe2203.noarch perl-DBD-MariaDB-1.21-3.oe2203.x86_64
    perl-DBI-1.643-3.oe2203.x86_64

    Complete!
    [root@superman-21 ~]# </pre>

👍 点赞,你的认可是我创作的动力!

⭐️ 收藏,你的青睐是我努力的方向!

✏️ 评论,你的意见是我进步的财富!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,406评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,732评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,711评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,380评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,432评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,301评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,145评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,008评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,443评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,649评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,795评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,501评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,119评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,731评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,865评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,899评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,724评论 2 354

推荐阅读更多精彩内容