Over the years this stuff has changed on MariaDB (basically MySQL for Linux). When I say ‘stuff’ I’m referring to how you secure MariaDB. Here’s three methods…from oldeest to newest:
VERSION 10.1.48-MariaDB:
Run from a command line, as root:
-
mysql_secure_installation
The above will log you in and ask if you want to set a new, root password….set a password.
- Login to mysql – even after having the above it will still accept any password. Run the following;
use mysql; update mysql.user set plugin=null where user='root'; flush privileges;Log out….you will no longer be able to login to MySQL with
virtually any password.
————————————————–
VERSION 10.3.3
This method was pretty involved and only required for one release as I recall:
sudo service mysql start cd /var/run sudo cp -rp ./mysqld ./mysqld.bak sudo service mysql stop sudo mv ./mysqld.bak ./mysqld
>> MYSQL IS NOW STOPPED, CONTINUE:
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
use mysql;
update user set password=PASSWORD("AppleBaum7560") where User='root';
update user set plugin="mysql_native_password" where User='root'; # THIS LINE
flush privileges;
quit;
————————————-
NEWER VERSIONS:
I believe newer versions simply use the server’s root password.
FROM THE WEB:
How It Works Now
-
- No Password Needed for OS Root: Running
sudo mysqlorsudo mariadblogs you straight in. - Safer by Default: This prevents users from leaving weak root passwords exposed in plain text files or command histories.
mysql_secure_installationStill Exists: The script is still useful, but its primary job now is removing anonymous users, disabling remote root logins, and deleting the test database. [1, 2, 3, 4, 5]
- No Password Needed for OS Root: Running
What if you still actually need a unique password?
If you have an application (like phpMyAdmin or a backup script) that absolutely requires a password to log in as root, you can switch back to the old method. Run this command inside MariaDB to set a password and disable the socket check:
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('your_new_password');
FLUSH PRIVILEGES;