前言

上篇文章链接:Linux下从0开始部署WordPress(一)

上篇说到了apache2的安装与配置,一直想着继续完成wordpress的教程,但拖延症发作,😄

复习一下wordpress的安装步骤:

  1. 有一台主机或vps(系统选linux,这里以debian为例)
  2. 安装web server(选apache2)
  3. 安装数据库(选mariadb)
  4. 安装php
  5. 配置wordpress

这篇就写一下安装数据库吧!


安装数据库

wordpress官方对数据库的要求:

MySQL5.7或更高版本 MariaDB 10.3或更高版本。

sun公司自从被oracle收购以后,原来sun公司旗下的产品都变成了oracle公司的资产,开源社区对oracle也是唯恐避之不及,现在debian仓库里连mysql都没有了。我不想去下安装包,所以这里数据库方案选择用mariadb。

一键安装

apt install mariadb-server

安装完成后,先用数据库自带的mysql_secure_installation进行简单的安全加固。执行下面这个命令,接下去会出现6个交互对话,需要选择yes/no。

mysql_secure_installation

第一个问题:是否切换到unix_socket认证。这里指mariadb的root账户身份认证是用密码还是unix_socket。unix_socket在简中互联网上几乎搜索不到什么有用的资料,出问题了不好解决,所以选n,用密码认证。

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]

第二个问题:是否修改root账户的密码。毫无疑问这里选Y。然后就是设置root账户的新密码了。

Change the root password? [Y/n]

第三个问题:是否移除匿名用户。选Y

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]

第四个问题:是否禁止root远程登录。选Y

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

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

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]

好了,到这一步,已经完成了mardiadb的安装和基础配置。接下来要开始进行建库了~


建库

首先进入mariadb的数据库命令行界面

mysql -u root -p

然后建库

create database wordpress;

创建一个wordpress账户专门来管理wordpress数据库,123456记得修改为自己想要的密码

create user wordpress@localhost identified by '123456';

给用户wordpress赋权管理wordpress数据库

grant all privileges on wordpress.* to wordpress@localhost identified by '123456';

使权限生效

flush privileges;

查看授权

show grants for wordpress@localhost;

看到输入如下的授权信息,说明建库、建用户、授权都完成了。

1690501010370.png


参考文章

  1. 关于mysql:为MariaDB根用户启用密码和unix_socket身份验证? https://www.codenong.com/41846000/
  2. mysqld/mariadb安全配置向导:mysql_secure_installation https://www.cnblogs.com/ccku/p/13657828.html
  3. 认证插件-Unix Socket https://runebook.dev/zh/docs/mariadb/authentication-plugin-unix-socket/index