有人说最好的密码就是你不用记忆的。auth_socket 插件和 MariaDB 的 unix_socket 让这种想法在 MySQL 上变成可能。
这两个插件虽然不是新发布,但在 MariaDB 10.4 上 unix_socket 已经默认安装,并且是身份验证方法之一。
插件的安装和使用
如上所述,这不是新功能,即使使用 Debian 团队维护的 .deb 安装包安装 MySQL,也会创建 root 用户,以便使用套接字身份验证,对于 MySQL 和 MariaDB 都是如此:
root@app:~# apt-cache show mysql-server-5.7 | grep -i maintainers
Original-Maintainer: Debian MySQL Maintainers
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
安装后,root 用户验证过程如下:
root@app:~# whoami
root
root@app:~# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select user, host, plugin, authentication_string from mysql.user where user = 'root';
+------+-----------+-------------+-----------------------+
| user | host | plugin | authentication_string |
+------+-----------+-------------+-----------------------+
| root | localhost | auth_socket | |
+------+-----------+---------