关于mariadb:Ubuntu2004-WSL-安装-MySQLMariaDB

8次阅读

共计 4972 个字符,预计需要花费 13 分钟才能阅读完成。

MariaDB 是一个开源的关系数据库管理系统。它最后被设计为 MySQL 的向后兼容二进制二进制替换。
MariaDB 由 MySQL 的原始开发人员和凋谢源代码社区开发和保护。
本指南阐明了如何在 Ubuntu 20.04(WSL) 上装置和爱护 MariaDB。

1、根底条件

本文装置环境为Ubuntu20.04 on WSL(Windows Subsystem for Linux),咱们假如您具备 root 用户或具备 sudo 权限的治理拜访权限。

2、装置 MariaDB

sudo apt update
sudo apt -y install mariadb-server

装置实现后,MariaDB 服务不会主动启动,请应用上面命令启动 MariaDB 服务:

sudo service mysql start

3、配置 MariaDB

MariaDB 服务有一个脚本叫做 mysql_secure_installation,它容许你能够很容易进步数据库服务器平安。
执行不带参数的脚本:

sudo mysql_secure_installation

该脚本将提醒您输出 root 明码,因为您尚未设置 root 明码,只需在此处按“Enter”。

Enter current password for root (enter for none):

在下一个提示符下,将要求您设置 MySQL root 用户的明码,输出 n

Set root password? [Y/n] n

在 Ubuntu 上,auth_socket 默认状况下插件会对 MariaDB 根用户进行身份验证。该插件通过查看调用客户端程序的本地零碎用户是否与指定的 MariaDB 用户名匹配来工作。

接下来,将要求您删除匿名用户,限度 root 用户对本地计算机的拜访,删除测试数据库并从新加载特权表。能够依照本人的爱好来批改:

# 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.
# 批改 root 用户明码
Set root password? [Y/n] n
 ... skipping.

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.
# 禁止 root 近程登录
Disallow root login remotely? [Y/n] n
 ... skipping.

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] n
 ... skipping.

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!

4、以 root 身份登录

要从命令行与 MariaDB 服务器进行交互,请应用 mysql 客户端实用程序或其别名 mariadb。此工具是作为 MariaDB 服务器软件包的依赖项装置的。

该 auth_socket 插件对 localhost 通过 Unix 套接字文件从进行连贯的用户进行身份验证。这意味着您不能通过提供明码来以 root 用户身份进行身份验证。

要以 root 用户身份登录 MariaDB 服务器(留神:以后形式下不再须要输出 -u root -p 参数了),请输出:

sudo mysql

将为您提供 MariaDB shell,如下所示:

# sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

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)]>
MariaDB [(none)]> quit
Bye

5、创立一个超级用户

在运行 MariaDB 的 Ubuntu 零碎上,默认状况下,将 root MariaDB 用户设置为应用 unix_socket 插件而不是应用明码进行身份验证。因为服务器应用 root 帐户执行日志轮换以及启动和进行服务器等工作,因而最好不要更改 root 帐户的身份验证详细信息。相同,软件包维护者倡议为基于明码的拜访创立一个独自的治理帐户。

如果要应用内部程序(例如 phpMyAdmin)以 root 用户身份登录 MariaDB 服务器,则有两个抉择。

第一个是将身份验证办法从更改 auth_socket 为 mysql_native_password。您能够通过运行以下命令来做到这一点:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
FLUSH PRIVILEGES;

举荐的第二个选项是创立一个新的专用治理用户,该用户能够拜访所有数据库:

GRANT ALL PRIVILEGES on *.* TO 'admin'@'%' IDENTIFIED BY 'very_strong_password' WITH GRANT OPTION;
SET PASSWORD FOR admin=PASSWORD('very_strong_password');
FLUSH PRIVILEGES;
QUIT;

您能够应用任何想要的名称来命名治理用户,然而请确保应用强明码。残缺的示例如下:

# sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

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)]> GRANT ALL PRIVILEGES on *.* TO 'admin'@'%' IDENTIFIED BY 'very_strong_password' WITH GRANT OPTION;
RD FOQuery OK, 0 rows affected (0.000 sec)

R admiMariaDB [(none)]> SET PASSWORD FOR admin=PASSWORD('very_strong_password');
Query OK, 0 rows affected (0.000 sec)
ES;
Q
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> QUIT;
Bye

您能够应用 mysqladmin 工具 (能够运行治理命令的客户端) 测试该新用户。以下 mysqladmin 命令以 admin 用户身份连贯到 MariaDB,并在提醒用户输出明码后返回版本号:

sudo mysqladmin -u admin -p version

将收到相似于以下的输入:

# sudo mysqladmin -u admin -p version
Enter password:
mysqladmin  Ver 9.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version          10.3.31-MariaDB-0ubuntu0.20.04.1
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 10 min 31 sec

Threads: 6  Questions: 140  Slow queries: 0  Opens: 38  Flush tables: 1  Open tables: 31  Queries per second avg: 0.221

6、MariaDB 应用

  • MariaDB 治理和根底配置
  • MariaDB 用户和数据库治理
  • MariaDB 导入测试数据库 employees

7、其余链接

  • 在 Ubuntu 原生零碎上装置 MariaDB:
    https://blog.csdn.net/fenglai…
  • How To Install MariaDB on Ubuntu 20.04:
    https://www.digitalocean.com/…
  • How To Import and Export Databases in MySQL or MariaDB:
    https://www.digitalocean.com/…
  • An Introduction to Queries in MySQL:
    https://www.digitalocean.com/…
  • How to Manage MySQL Databases and Users from the Command Line
    https://linuxize.com/post/how…
正文完
 0