I use linux OS with mysql database.

mysql CLI doesn't log some commands in ~/.mysql_history .
For example can not log create user.

How can force cli to store all commands in mysql_history ?
How can fix this problem ?

That behaviour is by design, which as far as I know you can not override.
By default all interactive statements are logged, including the CREATE USER statement, except when they contain password information.

Although you can add extra conditions that will prevent logging certain additional statements (set either the --histignore option or the MYSQL_HISTIGNORE environment variable) or completely stop logging with for instance the --batch switch, logging passwords is as far as I know not possible.

https://dev.mysql.com/doc/refman/5.7/en/mysql-logging.html

mysql ignores for logging purposes statements that match any pattern in the “ignore” list. By default, the pattern list is "*IDENTIFIED*:*PASSWORD*", to ignore statements that refer to passwords.

  • 1
    Whether possible or not, it's certainly not desirable. – jpmc26 Nov 19 at 4:29

Try to:

  • set MYSQL_HISTFILE environment variable explicitily

  • touch .mysql_history

  • chmod 600 .mysql_history

History in not written immediately, but when you exit the client.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.