概括
MariaDB是流行的关系数据库管理系统(RDBMS)之一,由一些原始开发人员从MySQL分配。
它是开源的,可以供社区和企业使用悠久的历史和大量知识来管理和维护。
要将其安装在固体和干净的操作系统OpenBSD上,这要归功于伟大的项目和社区维护的Package Management系统(“端口”)。
这篇文章显示了如何做。
环境
基本步骤
只有几个!
# pkg_add mariadb-server
# rcctl enable mysqld
# mysql_install_db
# rcctl start mysqld
# mysql_secure_installation
# # several questions will be given
所有描述都在下面。
教程
通过端口安装软件包
$ doas pkg_add mariadb-server
结果是:
quirks-6.122 signed on 2023-09-01T21:25:11Z
mariadb-server-10.9.4v1:(...): ok
mariadb-server-10.9.4v1: ok
The following new rcscripts were installed: /etc/rc.d/mysqld
See rcctl(8) for details.
New and changed readme(s):
/usr/local/share/doc/pkg-readmes/mariadb-server
如上所述,PKG-ReadMe以/usr/local/share/doc/pkg-readmes/mariadb-server
为单位。
激活守护程序
$ doas rcctl enable mysqld
运行mysql_install_db
创建默认数据库:
$ doas mysql_install_db
结果是:
WARNING: The host '(...)' could not be looked up with /usr/local/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in '/var/mysql' ...
OK
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is _mysql@localhost, it has no password either, but
you need to be the system '_mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Knowledgebase at https://mariadb.com/kb
You can start the MariaDB daemon with:
/etc/rc.d/mysqld start
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
开始守护程序
$ doas rcctl start mysqld
mysqld(ok)
运行mysql_secure_installation
$ doas mysql_secure_installation
开始(在问题之前)
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
给出了几个问题
实际上,它们取决于您的环境。
Q1:当前的根密码
首次必须不是。
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...
Q2:使用unix_socket身份验证代替根密码
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.
Q3:设置根密码
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!
Q4:删除匿名用户
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!
Q5:禁止远程登录
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!
Q6:删除测试数据库
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!
问题7:重新加载特权表
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!
结论
您可以确认您的守护程序很好:
$ doas rcctl check mysqld
mysqld(ok)
好吧,让我们用root
(超级用户:
)登录服务器
$ mysql -u root -p
输入密码后,必须受到欢迎:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.9.4-MariaDB OpenBSD port: mariadb-server-10.9.4v1
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)]>
命令行示例:
-- create database
CREATE DATABASE <database> \
CHARACTER SET utf8mb4 \
COLLATE utf8mb4_unicode_ci;
-- create user for it
GRANT ALL PRIVILEGES \
ON <database>.* \
TO <dbuser>@'localhost' \
IDENTIFIED BY '<dbpass>';
-- reload privileges
FLUSH PRIVILEGES;
ðµð—以数字方式存储快乐的存储