
| CREATE USER IDENTIFIED WITH 'caching_sha2_password' AS '$A$005IwwzH/s]6F.

Mysql> SHOW CREATE USER CREATE USER for |
Mysql list users password#
Mysql> CREATE USER IDENTIFIED BY 'MyPassword' PASSWORD EXPIRE įollowing is the SHOW CREATE USER query for the above created user − x.ycpOwCHw4U5DkqKEHmlbAB3QrvgjthpimTebHdY2' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT | | CREATE USER IDENTIFIED WITH 'caching_sha2_password' AS '$A$005eiknGyZ r]L◄T☻. Mysql> CREATE USER exampleUser IDENTIFIED BY '123456' įollowing query is retrieves/displays the CREATE statement used to create the above user. ExampleĪssume we have created a user using the CREATE statement as shown below − Where, name is the name of the user for which you need the create statement. Syntaxįollowing is the syntax of the SHOW CREATE USER Statement. The SHOW CREATE USER Statement is displays the CREATE statement used to create the specified user. To create a user account, the current account needs to have CREATE USER privilege, or the INSERT privilege for the MySQL system schema. LEFT JOIN er AS u ON u.user = l.user AND l.host = u.You can create a new user account in MySQL using the CREATE USER Statement. LEFT JOIN tracking.login_tracking AS l ON u.user = l.user AND l.host = u.hostĪnd to find users which are logged but could not be found from the mysql user table you can run: SELECT l.user, l.host For example, you can query: SELECT sqlgrants FROM commonschema.sqlshowgrants Or you can query for particular users, for example: SELECT sqlgrants FROM commonschema. You have two options though: Use commonschema 's sqlshowgrants view. To find at what time a user has logged in last you can run: SELECT u.user, u.host, l.ts 10 Answers Sorted by: 50 Nothing built-in. To find out, which users have logged in we can run the following query: SELECT * FROM tracking.login_tracking If something went wrong with the login trigger you find the needed information in the MySQL error log.


SET GLOBAL init_connect="CALL tracking.login_trigger()" | GRANT EXECUTE ON PROCEDURE tracking.login_trigger TO |Īs the last step we have to activate the stored procedure by hooking it into the login trigger hook: - SET GLOBAL init_connect="" SELECT CONCAT("GRANT EXECUTE ON PROCEDURE tracking.login_trigger TO '", user, host, "' ") AS query MySQL users with the SUPER privilege are not logged with the init_connect login trigger hook: - REVOKE EXECUTE ON PROCEDURE tracking.login_trigger FROM EXECUTE ON PROCEDURE tracking.login_trigger TO GRANTSs can be created with the following query: tee /tmp/grants.sql Then we have to grant the EXECUTE privilege to all users of the database which do not have the SUPER privilege. VALUES (SUBSTR(USER(), 1, instr(USER(), substr(USER(), instr(USER(), NOW()) INSERT INTO login_tracking (user, host, ts) Then we need a MySQL stored procedure which does the logging of the login: - DROP PROCEDURE IF EXISTS login_trigger The following MySQL login trigger helps to track the login of all non-super privileged MySQL users.įirst we need a table where to log the login of the users: - DROP DATABASE tracking MySQL database users who did not login within a defined period can be backuped and removed from the production MySQL database. In this situation it would be nice to know which MySQL database user has logged in within the last 6 months for example. The MySQL database becomes bigger and bigger, uses more and more RAM and disk space and the backup takes longer and longer.

MySQL hosting providers can easily loose the overview over their customers and which user or schema is still in use and which not.
