如何在openSUSE 15上安装MariaDB 10.5

时间:2020-02-23 14:40:56  来源:igfitidea点击:

我们是否正在寻找有关如何在openSUSE 15上安装MariaDB 1053的完整教程? MariaDB是MySQL的直接替代品。它是一个健壮,有弹性,可扩展且可靠的RDBMS,具有以前仅在昂贵的专有数据库中可用的功能。

撰写本文时,最新的稳定版本是MariaDB 10.5. 此版本可从MariaDB维护的Ubuntu/Debian/CentOS/Fedora/SUSE存储库中获得。立即在openSUSE 15上安装MariaDB 10.5,并享受其广泛的功能。

添加MariaDB ZYpp存储库

MariaDB为使用zypper来管理软件包的多个Linux发行版提供了MariaDB软件包存储库。通过运行以下命令为MariaDB添加ZYpp存储库。

获取存储库GPG密钥。

sudo rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
sudo zypper --gpg-auto-import-keys refresh

然后添加存储库:

sudo zypper addrepo --gpgcheck --refresh https://yum.mariadb.org/10.5/opensuse/15/x86_64 mariadb

执行输出:

Adding repository 'mariadb' ..............................................[done]
Repository 'mariadb' successfully added

URI         : https://yum.mariadb.org/10.5/sles/15/x86_64
Enabled     : Yes                                        
GPG Check   : Yes                                        
Autorefresh : Yes                                        
Priority    : 99 (default priority)                      

Repository priorities are without effect. All enabled repositories share the same priority.

在openSUSE 15上安装MariaDB 10.5

配置zypper存储库后,我们可以使用zypper安装MariaDB软件包。添加的存储库包含与MariaDB Server相关的软件包,包括服务器本身,客户端和实用程序,客户端库,插件和Mariabackup

要使用ZYpp安装MariaDB Server和客户端,请运行:

sudo zypper install MariaDB-server MariaDB-client

出现提示时,按y表示同意安装。

启动mariadb服务

安装后,启动MariaDB服务并将其设置为在启动时启动。

sudo systemctl enable --now mariadb

确认服务正在运行。

$systemctl status mariadb.service 
● mariadb.service - MariaDB 10.5.15 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Thu 2019-05-30 03:20:05 EDT; 13s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 3517 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_STA>
  Process: 3476 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VA>
  Process: 3475 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STAR>
 Main PID: 3486 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 19660)
   CGroup: /system.slice/mariadb.service
           └─3486 /usr/sbin/mysqld

要安装最常见的软件包,请执行以下命令:

sudo zypper install galera MariaDB-shared MariaDB-backup MariaDB-common

安全安装MariaDB

如果我们在生产环境中运行服务器,建议运行安全脚本以为root用户设置密码,删除测试数据库并为root用户禁用远程登录。

/usr/bin/mysql_secure_installation

通过运行以下脚本来保护数据库。

$sudo 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: <ENTER NEW PASSWORD>
Re-enter new password: <CONFIRM 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用户密码删除匿名用户禁止root用户远程登录删除测试数据库并对其进行访问

仅设置root密码,以下命令语法应适用于新安装。

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h linux-bswe password 'new-password'

完成后,使用没有密码的root用户测试访问。

$mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

如图所示,我们需要进行身份验证才能以root用户身份访问数据库控制台。

确认MariaDB版本。

MariaDB [(none)]> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 10.5.15-MariaDB |
+-----------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

现在,我们已在openSUSE 15上安装了MariaDB 10.5.