mysql_security_commands.sql 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. -- Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
  2. --
  3. -- This program is free software; you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation; version 2 of the License.
  6. --
  7. -- This program is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. -- GNU General Public License for more details.
  11. --
  12. -- You should have received a copy of the GNU General Public License
  13. -- along with this program; if not, write to the Free Software
  14. -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. # This set of commands will modify the predefined accounts of a MySQL installation
  16. # to increase security.
  17. # 1) Set passwords for the root account.
  18. # Note that the password 'ABC123xyz' will be replaced by a random string
  19. # when these commands are transferred to the server.
  20. SET @@old_passwords=1;
  21. UPDATE mysql.user SET Password=PASSWORD('ABC123xyz') WHERE User='root' and plugin='mysql_old_password';
  22. SET @@old_passwords=0;
  23. UPDATE mysql.user SET Password=PASSWORD('ABC123xyz') WHERE User='root' and plugin in ('', 'mysql_native_password');
  24. SET @@old_passwords=2;
  25. UPDATE mysql.user SET authentication_string=PASSWORD('ABC123xyz') WHERE User='root' and plugin='sha256_password';
  26. # 2) Drop the anonymous account.
  27. DELETE FROM mysql.user WHERE User='';
  28. # 3) Force the root user to change the password on first connect.
  29. UPDATE mysql.user SET Password_expired='Y' WHERE User='root';
  30. # In case this file is sent to a running server.
  31. FLUSH PRIVILEGES;