mysql_security_commands.sql 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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=0;
  21. UPDATE mysql.user SET Password=PASSWORD('ABC123xyz') WHERE User='root' and plugin in ('', 'mysql_native_password');
  22. SET @@old_passwords=2;
  23. UPDATE mysql.user SET authentication_string=PASSWORD('ABC123xyz') WHERE User='root' and plugin='sha256_password';
  24. # 2) Drop the anonymous account.
  25. DELETE FROM mysql.user WHERE User='';
  26. # 3) Force the root user to change the password on first connect.
  27. UPDATE mysql.user SET Password_expired='Y' WHERE User='root';
  28. # 4) remove remote accounts
  29. DELETE FROM mysql.user WHERE Host <> 'localhost';
  30. # 5) Drop the test database
  31. DROP DATABASE IF EXISTS test;
  32. DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
  33. # In case this file is sent to a running server.
  34. FLUSH PRIVILEGES;