60 openEuler 22.03-LTS 搭建MySQL数据库服务器-安装、运行和卸载

60 openEuler 22.03-LTS 搭建MySQL数据库服务器-安装、运行和卸载60.1 安装60.2 运行60.3 卸载

60 openEuler 22.03-LTS 搭建MySQL数据库服务器-安装、运行和卸载

60.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="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 clean all</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 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="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 makecache</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 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="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;"># dnf install mysql-server</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 ~]# dnf install mysql-server
    Last metadata expiration check: 0:45:47 ago on 2022年12月21日 星期三 17时18分58秒.
    Dependencies resolved.
    ====================================================================================================================================
    Package Architecture Version Repository Size
    ====================================================================================================================================
    Installing:
    mysql-server x86_64 8.0.28-1.oe2203 everything 23 M
    Installing dependencies:
    mariadb-config x86_64 4:10.5.16-1.oe2203 update 8.0 k
    mecab x86_64 0.996-2.oe2203 everything 371 k
    mysql x86_64 8.0.28-1.oe2203 OS 10 M
    mysql-common x86_64 8.0.28-1.oe2203 OS 30 k
    mysql-errmsg x86_64 8.0.28-1.oe2203 everything 545 k
    mysql-selinux noarch 1.0.0-2.oe2203 everything 35 k
    protobuf-lite x86_64 3.14.0-6.oe2203 update 217 k

    Transaction Summary

    Install 8 Packages

    Total download size: 35 M
    Installed size: 188 M
    Is this ok [y/N]: y
    Downloading Packages:
    (1/8): mysql-common-8.0.28-1.oe2203.x86_64.rpm 241 kB/s | 30 kB 00:00
    (2/8): mecab-0.996-2.oe2203.x86_64.rpm 1.2 MB/s | 371 kB 00:00
    (3/8): mysql-selinux-1.0.0-2.oe2203.noarch.rpm 784 kB/s | 35 kB 00:00
    (4/8): mysql-errmsg-8.0.28-1.oe2203.x86_64.rpm 1.3 MB/s | 545 kB 00:00
    (5/8): mariadb-config-10.5.16-1.oe2203.x86_64.rpm 113 kB/s | 8.0 kB 00:00
    (6/8): protobuf-lite-3.14.0-6.oe2203.x86_64.rpm 1.2 MB/s | 217 kB 00:00
    (7/8): mysql-8.0.28-1.oe2203.x86_64.rpm 7.6 MB/s | 10 MB 00:01
    (8/8): mysql-server-8.0.28-1.oe2203.x86_64.rpm 5.1 MB/s | 23 MB 00:04


    Total 7.1 MB/s | 35 MB 00:04
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
    Preparing : 1/1
    Installing : mariadb-config-4:10.5.16-1.oe2203.x86_64 1/8
    Installing : mysql-common-8.0.28-1.oe2203.x86_64 2/8
    Installing : mysql-8.0.28-1.oe2203.x86_64 3/8
    Installing : mysql-errmsg-8.0.28-1.oe2203.x86_64 4/8
    Installing : protobuf-lite-3.14.0-6.oe2203.x86_64 5/8
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 6/8
    Installing : mysql-selinux-1.0.0-2.oe2203.noarch 6/8
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 6/8
    libsemanage.semanage_direct_install_info: Overriding mysql module at lower priority 100 with module at priority 200.

    Installing : mecab-0.996-2.oe2203.x86_64 7/8
    Running scriptlet: mecab-0.996-2.oe2203.x86_64 7/8
    Running scriptlet: mysql-server-8.0.28-1.oe2203.x86_64 8/8
    Installing : mysql-server-8.0.28-1.oe2203.x86_64 8/8
    Running scriptlet: mysql-server-8.0.28-1.oe2203.x86_64 8/8
    Running scriptlet: mysql-selinux-1.0.0-2.oe2203.noarch 8/8
    Running scriptlet: mysql-server-8.0.28-1.oe2203.x86_64 8/8
    /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 : mysql-8.0.28-1.oe2203.x86_64 1/8
    Verifying : mysql-common-8.0.28-1.oe2203.x86_64 2/8
    Verifying : mecab-0.996-2.oe2203.x86_64 3/8
    Verifying : mysql-errmsg-8.0.28-1.oe2203.x86_64 4/8
    Verifying : mysql-selinux-1.0.0-2.oe2203.noarch 5/8
    Verifying : mysql-server-8.0.28-1.oe2203.x86_64 6/8
    Verifying : mariadb-config-4:10.5.16-1.oe2203.x86_64 7/8
    Verifying : protobuf-lite-3.14.0-6.oe2203.x86_64 8/8

    Installed:
    mariadb-config-4:10.5.16-1.oe2203.x86_64 mecab-0.996-2.oe2203.x86_64 mysql-8.0.28-1.oe2203.x86_64
    mysql-common-8.0.28-1.oe2203.x86_64 mysql-errmsg-8.0.28-1.oe2203.x86_64 mysql-selinux-1.0.0-2.oe2203.noarch
    mysql-server-8.0.28-1.oe2203.x86_64 protobuf-lite-3.14.0-6.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="n29" 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 mysql</pre>

    例如示例命令如下:

    <pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n31" 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 mysql
    mysql-server-8.0.28-1.oe2203.x86_64
    mysql-selinux-1.0.0-2.oe2203.noarch
    mysql-errmsg-8.0.28-1.oe2203.x86_64
    mysql-common-8.0.28-1.oe2203.x86_64
    mysql-8.0.28-1.oe2203.x86_64
    [root@superman-21 ~]# </pre>

60.2 运行

  1. 修改配置文件。

    1. 在root权限下创建my.cnf文件,其中文件路径(包括软件安装路径basedir、数据路径datadir等)根据实际情况修改。

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n39" 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: pre-wrap; 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>

      编辑my.cnf内容如下:

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n41" 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: pre-wrap; 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;">log-error=/data/mysql/log/mysqlerr.log
      pid-file=/data/mysql/run/mysqld.pid
      [mysqldump]
      quick
      [mysql]
      no-auto-rehash
      [client]
      default-character-set=utf8
      [mysqld]
      basedir=/usr/share/mysql
      socket=/data/mysql/run/mysql.sock
      tmpdir=/data/mysql/tmp
      datadir=/data/mysql/data
      lc-messages-dir=/usr/share/mysql
      authentication_policy=mysql_native_password
      port=3306
      user=mysql</pre>

    2. 确保my.cnf配置文件修改正确。

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n44" 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: pre-wrap; 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;"># cat /etc/my.cnf</pre>

      [图片上传失败...(image-612c7b-1682256412097)]

      注意: 其中basedir为软件安装路径,请根据实际情况修改。

      例如示例命令如下:

      <pre class="md-fences mock-cm md-end-block" 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: pre-wrap; 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
      [mysqld_safe]
      log-error=/data/mysql/log/mysqlerr.log
      pid-file=/data/mysql/run/mysqld.pid
      [mysqldump]
      quick
      [mysql]
      no-auto-rehash
      [client]
      default-character-set=utf8
      [mysqld]
      basedir=/usr/share/mysql
      socket=/data/mysql/run/mysql.sock
      tmpdir=/data/mysql/tmp
      datadir=/data/mysql/data
      lc-messages-dir=/usr/share/mysql
      authentication_policy=mysql_native_password
      port=3306
      user=mysql
      [root@superman-21 ~]# </pre>

    3. 设置socket软连接。

      <pre class="md-fences mock-cm md-end-block" 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: pre-wrap; 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/mysql/run/mysql.sock /var/lib/mysql/mysql.sock</pre>

      例如示例命令如下:

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n53" 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: pre-wrap; 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/mysql/run/mysql.sock /var/lib/mysql/mysql.sock
      [root@superman-21 ~]# </pre>

  2. 在root权限下初始化数据库。

    [图片上传失败...(image-18c3ac-1682256412097)]

    说明: 本步骤倒数第2行中有初始密码,请注意保存,登录数据库时需要使用。

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n58" 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: pre-wrap; 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;"># mysqld --defaults-file=/etc/my.cnf --initialize</pre>

    例如示例命令如下:

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n60" 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: pre-wrap; 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 ~]# mysqld --defaults-file=/etc/my.cnf --initialize
    2022-12-21T11:46:52.711486Z 0 [System] [MY-013169] [Server] /usr/libexec/mysqld (mysqld 8.0.28) initializing of server in progress as process 9296
    2022-12-21T11:46:52.719415Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
    2022-12-21T11:46:52.929564Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
    2022-12-21T11:46:53.791786Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: +KmMm/t/q8x4
    [root@superman-21 ~]# </pre>

    查看打印信息,打印信息中包括“initializing of server has completed”表示初始化数据库完成,且打印信息中“A temporary password is generated for root@localhost: +KmMm/t/q8x4”的“+KmMm/t/q8x4”为初始密码。

  3. 启动数据库。

    [图片上传失败...(image-b5fef8-1682256412097)]

    注意: 如果第一次启动数据库服务,以root用户启动数据库,则启动时会提示缺少mysql.log文件而导致失败。使用mysql用户启动之后,会在/data/mysql/log目录下生成mysql.log文件,再次使用root用户启动则不会报错。

    在root权限下启动MySQL数据库。

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n67" 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: pre-wrap; 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 mysqld </pre>

    例如示例命令如下:

    <pre class="md-fences mock-cm md-end-block" 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: pre-wrap; 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 mysqld
    [root@superman-21 ~]#
    [root@superman-21 ~]# systemctl status mysqld
    ● mysqld.service - MySQL 8.0 database server
    Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
    Active: active (running) since Wed 2022-12-21 19:51:29 CST; 6s ago
    Process: 9349 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 9372 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
    Main PID: 9408 (mysqld)
    Status: "Server is operational"
    Tasks: 38 (limit: 21420)
    Memory: 362.6M
    CGroup: /system.slice/mysqld.service
    └─ 9408 /usr/libexec/mysqld --basedir=/usr

    12月 21 19:51:20 superman-21 systemd[1]: Starting MySQL 8.0 database server...
    12月 21 19:51:24 superman-21 mysqld[9408]: 2022-12-21T11:51:24.402543Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld >
    12月 21 19:51:24 superman-21 mysqld[9408]: 2022-12-21T11:51:24.447428Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has st>
    12月 21 19:51:28 superman-21 mysqld[9408]: 2022-12-21T11:51:28.034838Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has en>
    12月 21 19:51:29 superman-21 mysqld[9408]: 2022-12-21T11:51:29.808010Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is se>
    12月 21 19:51:29 superman-21 mysqld[9408]: 2022-12-21T11:51:29.808074Z 0 [System] [MY-013602] [Server] Channel mysql_main configure>
    12月 21 19:51:29 superman-21 mysqld[9408]: 2022-12-21T11:51:29.830258Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready f>
    12月 21 19:51:29 superman-21 mysqld[9408]: 2022-12-21T11:51:29.830320Z 0 [System] [MY-011323] [Server] X Plugin ready for connectio>
    12月 21 19:51:29 superman-21 systemd[1]: Started MySQL 8.0 database server.
    [root@superman-21 ~]#</pre>

  4. 登录数据库。

    [图片上传失败...(image-e25e48-1682256412097)]

    说明:

    • 提示输入密码时,请输入2产生的初始密码。
    • 如果采用官网RPM安装方式,则mysql文件在/usr/bin目录下。登录数据库的命令根据实际情况修改。

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n79" 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: pre-wrap; 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 -uroot -p</pre>

    例如示例命令如下:

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n81" 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: pre-wrap; 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 -uroot -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.28

    Copyright (c) 2000, 2022, Oracle and/or its affiliates.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql></pre>

  5. 配置数据库帐号密码。

    1. 登录数据库以后,修改通过root用户登录数据库的密码。

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n87" 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: pre-wrap; 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> alter user 'root'@'localhost' identified by "123456";</pre>

      例如示例命令如下:

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n89" 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: pre-wrap; 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> alter user 'root'@'localhost' identified by "123456";
      Query OK, 0 rows affected (0.01 sec)

      mysql> </pre>

    2. 创建全域root用户(允许root从其他服务器访问)。

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n92" 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: pre-wrap; 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> create user 'root'@'%' identified by '123456';</pre>

      例如示例命令如下:

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n94" 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: pre-wrap; 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> create user 'root'@'%' identified by '123456';
      Query OK, 0 rows affected (0.00 sec)

      mysql> </pre>

    3. 进行授权。

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n97" 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: pre-wrap; 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> grant all privileges on . to 'root'@'%';
      mysql> flush privileges;</pre>

      例如示例命令如下:

      <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n99" 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: pre-wrap; 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> grant all privileges on . to 'root'@'%';
      Query OK, 0 rows affected (0.01 sec)

      mysql> flush privileges;
      Query OK, 0 rows affected (0.00 sec)

      mysql> </pre>

  6. 退出数据库。

    执行 \q 或者 exit 退出数据库。

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n103" 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: pre-wrap; 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> \q
    mysql> exit</pre>

    例如示例命令如下:

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n105" 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: pre-wrap; 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> \q
    Bye
    [root@superman-21 ~]#
    mysql> exit
    Bye
    [root@superman-21 ~]# </pre>

60.3 卸载

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

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n111" 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: pre-wrap; 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 mysqld</pre>

    例如示例命令如下:

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n113" 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: pre-wrap; 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 mysqld
    [root@superman-21 ~]# </pre>

  2. 在root权限下执行dnf remove mysql命令卸载MySQL。

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n116" 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: pre-wrap; 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 mysql</pre>

    例如示例命令如下:

    <pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n118" 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: pre-wrap; 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 mysql
    Dependencies resolved.
    ====================================================================================================================================
    Package Architecture Version Repository Size
    ====================================================================================================================================
    Removing:
    mysql x86_64 8.0.28-1.oe2203 @OS 59 M
    Removing dependent packages:
    mysql-server x86_64 8.0.28-1.oe2203 @everything 117 M
    Removing unused dependencies:
    mariadb-config x86_64 4:10.5.16-1.oe2203 @update 345
    mecab x86_64 0.996-2.oe2203 @everything 2.1 M
    mysql-common x86_64 8.0.28-1.oe2203 @OS 185 k
    mysql-errmsg x86_64 8.0.28-1.oe2203 @everything 9.1 M
    mysql-selinux noarch 1.0.0-2.oe2203 @everything 49 k
    protobuf-lite x86_64 3.14.0-6.oe2203 @update 779 k

    Transaction Summary

    Remove 8 Packages

    Freed space: 188 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: mysql-server-8.0.28-1.oe2203.x86_64 1/1
    Running scriptlet: mysql-server-8.0.28-1.oe2203.x86_64 1/8
    Erasing : mysql-server-8.0.28-1.oe2203.x86_64 1/8
    Running scriptlet: mysql-server-8.0.28-1.oe2203.x86_64 1/8
    Erasing : mysql-errmsg-8.0.28-1.oe2203.x86_64 2/8
    Erasing : mysql-8.0.28-1.oe2203.x86_64 3/8
    Erasing : mysql-common-8.0.28-1.oe2203.x86_64 4/8
    Erasing : mariadb-config-4:10.5.16-1.oe2203.x86_64 5/8
    警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave

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

    Erasing : mecab-0.996-2.oe2203.x86_64 7/8
    Running scriptlet: mecab-0.996-2.oe2203.x86_64 7/8
    Erasing : protobuf-lite-3.14.0-6.oe2203.x86_64 8/8
    Running scriptlet: protobuf-lite-3.14.0-6.oe2203.x86_64 8/8
    Verifying : mariadb-config-4:10.5.16-1.oe2203.x86_64 1/8
    Verifying : mecab-0.996-2.oe2203.x86_64 2/8
    Verifying : mysql-8.0.28-1.oe2203.x86_64 3/8
    Verifying : mysql-common-8.0.28-1.oe2203.x86_64 4/8
    Verifying : mysql-errmsg-8.0.28-1.oe2203.x86_64 5/8
    Verifying : mysql-selinux-1.0.0-2.oe2203.noarch 6/8
    Verifying : mysql-server-8.0.28-1.oe2203.x86_64 7/8
    Verifying : protobuf-lite-3.14.0-6.oe2203.x86_64 8/8

    Removed:
    mariadb-config-4:10.5.16-1.oe2203.x86_64 mecab-0.996-2.oe2203.x86_64 mysql-8.0.28-1.oe2203.x86_64
    mysql-common-8.0.28-1.oe2203.x86_64 mysql-errmsg-8.0.28-1.oe2203.x86_64 mysql-selinux-1.0.0-2.oe2203.noarch
    mysql-server-8.0.28-1.oe2203.x86_64 protobuf-lite-3.14.0-6.oe2203.x86_64

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

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

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

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

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

推荐阅读更多精彩内容