阡陌 发表于 2023-12-28 21:36:37

Ubuntu 安装 MariaDB 数据库服务


MariaDB 由 MySQL 的创始人 Michael Widenius 主导开发,是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可。MariaDB 的目的是完全兼容 MySQL,包括 API 和命令行,使之能轻松成为 MySQL 的代替品。在存储引擎方面,使用 XtraDB 来代替 MySQL 的 InnoDB。

MariaDB 的 API 和协议兼容 MySQL,另外又添加了一些功能,以支持本地的非阻塞操作和进度报告。这意味着,所有使用 MySQL 的连接器、库和应用程序也将会在 MariaDB 下工作。

安装 MariaDB:
```shell
sudo apt install mariadb-server mariadb-client
```

检查 MariaDB 的状态
```shell
systemctl status mariadb
```

输出:
```shell
● mariadb.service - MariaDB 10.6.12 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2023-12-11 17:13:04 UTC; 59s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 21940 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 21941 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21943 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl>
    Process: 21982 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21984 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 21972 (mariadbd)
   Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 2220)
   Memory: 60.8M
      CPU: 1.084s
   CGroup: /system.slice/mariadb.service
             └─21972 /usr/sbin/mariadbd

```

如果 MariaDB 未处于活动状态,则启动它:
```text
systemctl start mariadb
```

使用以下命令在启动时自动启动 MariaDB:
```text
systemctl enable mariadb
```

数据库安全相关初始化:
```text
sudo mysql_secure_installation
```

交互:
```text
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 n#是否切换 unix_socket 身份验证
... skipping.

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

Change the root password? y#是否更改 root 登录密码
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#是否删除匿名用户
... 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#是否禁止 root 远程登录
... 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#是否删除测试数据库
- 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#是否重新加载权限表
... 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!
```

登录 MariaDB:
```text
mariadb -u root -p
```

退出 MariaDB:
```text
exit
```

检查 MariaDB 版本:
```text
mariadb --version
```

输出:
```text
mariadbVer 15.1 Distrib 10.6.12-MariaDB, for debian-linux-gnu (x86_64) usingEditLine wrapper
```


页: [1]
查看完整版本: Ubuntu 安装 MariaDB 数据库服务