MySQL 8.0 UN-securing root

by Mark Nielsen
Copyright July 2023


Why insecure root in MySQL 8.0 and how is root secured? In 8.0 root is password less, but it is authorized by the plugin auth_socket, which means in Linux you must login as user root under Linux in order to login into the socket file of mysql as root for mysql. Basically, if you are root on Linux you can do anything anyways. So why unsecure it? Because of mysql history file. I have to login into Linux and sudo to root and then the mysql history file can't be used, which can be annoying. Also, if I su -l root after, the arrows don't work in the mysql history. Perhaps I should solve the mysql history file directly. But this is for non-production, so I don't really have an issue. I still keep root only logging in locally.
  1. Links
  2. How to do it
  3. Saving passwords
  4. Expect and automation


Links



How to do it

Change the password. Here is a record of commands I used.

mysql> select user,host,plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| debian-sys-maint | localhost | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | auth_socket           |
+------------------+-----------+-----------------------+

mysql> alter user root@localhost IDENTIFIED WITH caching_sha2_password;
Query OK, 0 rows affected (0.10 sec)

mysql> alter user root@localhost identified by 'BAD_PASSWORD';
Query OK, 0 rows affected (0.11 sec)

mysql> select user,host,plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| debian-sys-maint | localhost | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+


Saving password

Also, with the mysql client, you configure the password automatically in two ways:



Expect and automation

To automate installation do one of the two things:

Expect