SELECT host,
user,
account_locked,
plugin,
password_expired,
password_last_changed,
password_lifetime
FROM mysql.user;
SHOW CREATE USER user@host;
SHOW GRANTS FOR user@host;
CREATE USER 'myuser'@'myhost.mydomain' IDENTIFIED BY RANDOM PASSWORD;
Generated random passwords have a length of 20 characters. This length is controlled by the generated_random_password_length system variable.This option not available in older versions of MySQL or derivatives.If you need control over what the password will be, then use...
CREATE USER 'myuser'@'myhost.mydomain' IDENTIFIED BY 'myPassword'
GRANT ALL PRIVILEGES ON database.* TO myuser@'%';
To limit login attempts (e.g. to reduce risks of a Denial Of Service style of attack)...
GRANT USAGE ON *.* TO 'myuser'@'myhost' WITH MAX_CONNECTIONS_PER_HOUR 50;
Limits number of connection attempts by 'myuser'@'myhost to any database to 50 per hourSee other pages for examples of specific GRANT options...
REVOKE ALL PRIVILEGES ON database.* FROM myuser@%;
ALTER USER 'myuser'@'myhost.mydomain' IDENTIFIED BY RANDOM PASSWORD;
or
SET PASSWORD FOR 'myuser'@'myhost.mydomain' TO RANDOM;
If you need control over what the password will be, you can use...
ALTER USER 'myuser'@'myhost.mydomain' IDENTIFIED BY 'myPassword'
DROP USER 'myuser'@'localhost';
Default: 20
If you have the Percona Toolkit installed you can dump the CREATE statements and GRANTs for all users...
pt-show-grants --ask-pass --user root
If you have lost the root password, you can do this to reset it. Note that this DOES require an outage.
systemctl stop mysql
mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
USE mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'New-Password';
exit
ps aux | grep mysqld
kill -9 9999999
systemctl start mysql