A potential downside with creating a mysql@localhost account with unix_socket authentication is that the mysql Unix user's default shell is /sbin/nologin on a lot of systems, so it might be kind of awkward for DBAs to use the account with unix_socket authentication.
For example, if we create the MariaDB user with unix_socket authentication:
MariaDB [(none)]> INSTALL SONAME 'auth_socket';
|
Query OK, 0 rows affected (0.002 sec)
|
|
MariaDB [(none)]> CREATE USER mysql@localhost IDENTIFIED VIA unix_socket;
|
Query OK, 0 rows affected (0.000 sec)
|
|
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO mysql@localhost WITH GRANT OPTION;
|
Query OK, 0 rows affected (0.000 sec)
|
And then if we try to log in with the Unix account on RHEL 7:
[ec2-user@ip-172-30-1-236 ~]$ sudo passwd mysql
|
Changing password for user mysql.
|
New password:
|
Retype new password:
|
passwd: all authentication tokens updated successfully.
|
[ec2-user@ip-172-30-1-236 ~]$ su -l mysql
|
Password:
|
Last failed login: Mon Jan 21 03:55:21 UTC 2019 on pts/0
|
There was 1 failed login attempt since the last successful login.
|
This account is currently not available.
|
[ec2-user@ip-172-30-1-236 ~]$ getent passwd mysql
|
mysql:x:997:994:MySQL server:/var/lib/mysql:/sbin/nologin
|
[ec2-user@ip-172-30-1-236 ~]$ cat /etc/redhat-release
|
Red Hat Enterprise Linux Server release 7.5 (Maipo)
|
It fails if we actually try to login as the user, because the user's default shell is /sbin/nologin.
So to make this work, you'd either have to change the Unix user's default shell or find ways to authenticate as the Unix user without logging into a shell, such as by using sudo, like in the following example:
[ec2-user@ip-172-30-1-236 ~]$ sudo -u mysql mysql -u mysql
|
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
Your MariaDB connection id is 12
|
Server version: 10.3.12-MariaDB MariaDB Server
|
|
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)]> SELECT CURRENT_USER();
|
+-----------------+
|
| CURRENT_USER() |
|
+-----------------+
|
| mysql@localhost |
|
+-----------------+
|
1 row in set (0.000 sec)
|
If this mysql@localhost account would only be intended for automated things like logrotate and package installation scripts, then maybe this isn't a problem.
If there is no strong demand for this to happen fast due to any policies or whatever, I would rather wait for the automatic fallback. The change of the default authentication method seems to have caused considerable confusion among users, at least I have seen questions about why it is happening and how to get back to the usual password authentication on multiple occasions on resources like stackoverflow and such.