在各个Linux发行版中的MariaDB

在过去几年里,几乎所有的Linux发行版都在从MySQL迁移到MariaDB。

根据https://mariadb.com/kb/en/library/mariadb-package-repository-setup-and-usage/中提到的,

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

如果进行存储库设置,则可以安装最新版本的MariaDB GA,但我已经确认了每个常用发行版提供的 MariaDB 可在其标准存储库中安装的版本、安装命令和服务启动方法。

DistributionMariaDB / MySQLversioninstallationstart service備考CentOS 6MySQL5.1yum -y install mysql-serversevice mysqld start
CentOS 7MariaDB5.5yum -y install mariadb-serversystemctl start mariadb
Debian 8 (jessie)MariaDB10.0apt -y install mariadb-serversystemctl start mysql
Debian 9 (stretch)MariaDB10.1apt -y install mysql-server / apt -y install mariadb-serversystemctl start mysql / systemctl start mariadbmysql aliased to mariadbUbuntu 16.04 LTSMariaDB10.0apt -y install mariadb-serversystemctl start mysql
Ubuntu 18.04 LTSMariaDB10.1apt -y install mariadb-serversystemctl start mysql / systemctl start mysqld / systemctl start mariadb
SLES 12 SP2MariaDB10.0zypper -n install mariadbsystemctl start mysql

根据发行版的不同,软件包名称、服务名称可能会有所不同,或者采用别名,但最近的版本似乎正在统一到MariaDB上。

要安装最新版本的GA 10.3,需要从MariaDB官方软件源进行安装。

通过mysql(MariaDB监视器)连接到mysqld。

在最近的Debian/Ubuntu版本中,由于启用了unix_socket插件,非操作系统的root用户将无法通过mysql连接到MariaDB服务器。

$ whoami
vagrant
$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

在执行mysql(mariadb)命令前,您可以使用sudo或者sudo su-等方式切换到root用户,然后连接到数据库服务器。

$ sudo mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT user,host,password,plugin FROM mysql.user;
+------+-----------+----------+-------------+
| user | host      | password | plugin      |
+------+-----------+----------+-------------+
| root | localhost |          | unix_socket |
+------+-----------+----------+-------------+

禁用unix_socket插件。

MariaDB [mysql]> update mysql.user set plugin='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> select user,host,plugin from mysql.user;
+-------+-----------+--------+
| user  | host      | plugin |
+-------+-----------+--------+
| root  | localhost |        |
+-------+-----------+--------+

请参考以下链接:https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/

UNIX_SOCKET插件默认安装在Ubuntu 15.10及以上版本以及Debian测试版本的新安装中。

附注:由于在Markdown中创建表格非常繁琐,我使用了https://donatstudios.com/CsvToMarkdownTable这个工具。