I have been bitten several times by the 'debian-sys-maint' user that is installed by default on the mysql-server packages installed from the Ubuntu repositories.
Generally what happens is I pull a fresh copy of our production database (which is not running on Debian/Ubuntu) for troubleshooting or new development and forget to exclude the mysql.user table hence losing the debian-sys-maint user.
If we add new mysql users for whatever reason, I have to 'merge' these into my development environment as opposed to just overlaying the table.
Without the user my system still seems functional, but plagued with errors such as:
sudo /etc/init.d/mysql restart
Stopping MySQL database server: mysqld...failed.
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'
- What is debian-sys-maint used for?
- Is there a better way for the package maintainers to do what they're trying to do?
- What is the easiest way to restore it after I've lost it?
- What is the correct/minimal set of privileges for this user?
- Seems like poor idea to 'grant all privileges on *.* ...'
Edit
Additional question - Is the password in /etc/mysql/debian.cnf already hashed or is this the plaintext password? It matters when you go to recreate the user and I never seem to get it right on the first try.
Thanks
One major thing it is used for is telling the server to roll the logs. It needs at least the reload and shutdown privilege.
See the file /etc/logrotate.d/mysql-server
It is used by the
/etc/init.d/mysql
script to get the status of the server. It is used to gracefully shutdown/reload the server.Here is the quote from the README.Debian
The best plan is to simply not lose it. If you really lose the password, reset it, using another account. If you have lost all admin privileges on the mysql server follow the guides to reset the root password, then repair the
debian-sys-maint
.You could use a command like this to build a SQL file that you can use later to recreate the account.
The password is not hashed/encrypted when installed, but new versions of mysql now have a way to encrypt the credentials (see: https://serverfault.com/a/750363).
The debian-sys-maint user is by default a root equivalent. It is used by certain maintenance scripts on Debian systems, and as a side-effect, allows users with root access on the box to view the plaintext password in /etc/mysql/debian.cnf (good or bad?)
You can re-create the user by:
Just make sure the password matches that in /etc/mysql/debian.cnf
I wanted to just comment, but I think correct syntax deserves it's own entry. This will create the debian-sys-maint user:
If you still have the /etc/mysql/debian.cnf file, just use the password in there.
Feel free to come up with a more
paranoidsecure solution.You could also:
Which will give you the option to recreate the debian-sys-maint user. Existing users and databases are safe.
If you need to add the
debian-sys-maint
user just forlogrotate.d
purposes, you should not grantALL PRIVILEGES
or theGRANT OPTION
-- this is an unnecessary giant security hole. Instead, you can just add the user with theRELOAD
privilege like this (assuming you are accessing your db asroot
, and you replace xxxxxx with your password)2019 Update
This answer may be out of date -- please see the strongly opinionated comments below.
Instead of
I think
because the password is not hashed ...?
debian-sys-maint required permissions
Other answers have sufficiently addressed everything except the minimum set of permissions that are required for the debian-sys-maint user. Many of the answers here are simply wrong in that respect, and in fact dangerous. Do not reduce debian-sys-maint privileges (including the grant option) without reading and understanding below:
The Debian maintainer did not give all privileges to the user capriciously. Here is what is required, where and why. Some of these privileges are supersets of others, but I will list them independently in case you want to customize things and remove the requirement for them:
The last one is, of course, the major requirement for privileges. The man page for mysql_upgrade states that:
WARNING If you decide to cut down on the privileges that debian-sys-maint has, then make sure you are prepared to manually handle any future debian security updates and/or upgrades that touch MySQL. If you perform an update on the MySQL packages with a reduced debian-sys-maint privilege, and if mysql_upgrade cannot complete as a result, it may leave your database in an undefined (read broken) state. Reducing privileges may not have any apparent day-to-day issues until an update comes along, so do not go by the fact that you have already reduced privileges with no harmful effects as a basis for thinking it is safe.
As a side note to this, take a look at this mysqlperformanceblog post for reasons why you might want to disable the debian-specific stuff.
When using MySQL 5.6+, I would recommend using the
mysql_config_editor
command to create an entry for the user'debian-sys-maint'@'localhost'
using the relevant password, meaning the password does not need to be stored in plain text on the server.mysql_config_editor set --login-path=debian-sys-maint --host=localhost --user=debian-sys-maint --password
Following this, the debian specific config file
/etc/mysql/debian.cnf
can be altered so the username and password details are not stored in the file.Finally, alter the logrotate file for MySQL so that it uses the login details stored in the
~/.mylogin.cnf
file instead of the debian specific file by replacing/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf
with
/usr/bin/mysqladmin --login-path=debian-sys-maint
Hope this helps :)
Dave