Security in Mysql Abstract
Total Page:16
File Type:pdf, Size:1020Kb
Security in MySQL Abstract This is the MySQL Security Guide extract from the MySQL 5.7 Reference Manual. For legal information, see the Legal Notices. For help with using MySQL, please visit the MySQL Forums, where you can discuss your issues with other MySQL users. Document generated on: 2021-09-24 (revision: 70892) Table of Contents Preface and Legal Notices .................................................................................................................. v 1 Security .......................................................................................................................................... 1 2 General Security Issues .................................................................................................................. 3 2.1 Security Guidelines ............................................................................................................... 3 2.2 Keeping Passwords Secure .................................................................................................. 4 2.2.1 End-User Guidelines for Password Security ................................................................ 5 2.2.2 Administrator Guidelines for Password Security ........................................................... 6 2.2.3 Passwords and Logging ............................................................................................. 6 2.2.4 Password Hashing in MySQL ..................................................................................... 7 2.3 Making MySQL Secure Against Attackers ............................................................................ 13 2.4 Security-Related mysqld Options and Variables ................................................................... 15 2.5 How to Run MySQL as a Normal User ................................................................................ 15 2.6 Security Considerations for LOAD DATA LOCAL ................................................................. 16 2.7 Client Programming Security Guidelines .............................................................................. 19 3 Postinstallation Setup and Testing ................................................................................................. 21 3.1 Initializing the Data Directory ............................................................................................... 21 3.2 Starting the Server ............................................................................................................. 27 3.2.1 Troubleshooting Problems Starting the MySQL Server ............................................... 27 3.3 Testing the Server .............................................................................................................. 29 3.4 Securing the Initial MySQL Account .................................................................................... 31 3.5 Starting and Stopping MySQL Automatically ........................................................................ 33 4 Access Control and Account Management ..................................................................................... 35 4.1 Account User Names and Passwords .................................................................................. 36 4.2 Privileges Provided by MySQL ............................................................................................ 38 4.3 Grant Tables ...................................................................................................................... 45 4.4 Specifying Account Names ................................................................................................. 52 4.5 Access Control, Stage 1: Connection Verification ................................................................. 54 4.6 Access Control, Stage 2: Request Verification ..................................................................... 57 4.7 Adding Accounts, Assigning Privileges, and Dropping Accounts ............................................ 59 4.8 Reserved Accounts ............................................................................................................. 62 4.9 When Privilege Changes Take Effect .................................................................................. 62 4.10 Assigning Account Passwords ........................................................................................... 63 4.11 Password Management ..................................................................................................... 64 4.12 Server Handling of Expired Passwords .............................................................................. 67 4.13 Pluggable Authentication ................................................................................................... 69 4.14 Proxy Users ..................................................................................................................... 72 4.15 Account Locking ............................................................................................................... 80 4.16 Setting Account Resource Limits ....................................................................................... 80 4.17 Troubleshooting Problems Connecting to MySQL ............................................................... 83 4.18 SQL-Based Account Activity Auditing ................................................................................. 87 5 Using Encrypted Connections ........................................................................................................ 89 5.1 Configuring MySQL to Use Encrypted Connections .............................................................. 91 5.2 Encrypted Connection TLS Protocols and Ciphers ............................................................... 95 5.3 Creating SSL and RSA Certificates and Keys .................................................................... 102 5.3.1 Creating SSL and RSA Certificates and Keys using MySQL ..................................... 102 5.3.2 Creating SSL Certificates and Keys Using openssl .................................................. 105 5.3.3 Creating RSA Keys Using openssl .......................................................................... 110 5.4 SSL Library-Dependent Capabilities ................................................................................... 110 5.5 Connecting to MySQL Remotely from Windows with SSH ................................................... 112 6 Security Plugins .......................................................................................................................... 113 6.1 Authentication Plugins ....................................................................................................... 114 iii Security in MySQL 6.1.1 Native Pluggable Authentication .............................................................................. 114 6.1.2 Old Native Pluggable Authentication ....................................................................... 115 6.1.3 Migrating Away from Pre-4.1 Password Hashing and the mysql_old_password Plugin 116 6.1.4 Caching SHA-2 Pluggable Authentication ................................................................ 120 6.1.5 SHA-256 Pluggable Authentication .......................................................................... 125 6.1.6 Client-Side Cleartext Pluggable Authentication ........................................................ 129 6.1.7 PAM Pluggable Authentication ................................................................................ 130 6.1.8 Windows Pluggable Authentication .......................................................................... 141 6.1.9 LDAP Pluggable Authentication .............................................................................. 146 6.1.10 No-Login Pluggable Authentication ........................................................................ 160 6.1.11 Socket Peer-Credential Pluggable Authentication ................................................... 163 6.1.12 Test Pluggable Authentication ............................................................................... 165 6.1.13 Pluggable Authentication System Variables ........................................................... 167 6.2 The Connection-Control Plugins ........................................................................................ 184 6.2.1 Connection-Control Plugin Installation ..................................................................... 184 6.2.2 Connection-Control System and Status Variables .................................................... 188 6.3 The Password Validation Plugin ........................................................................................ 190 6.3.1 Password Validation Plugin Installation ................................................................... 192 6.3.2 Password Validation Plugin Options and Variables .................................................. 193 6.4 The MySQL Keyring ......................................................................................................... 198 6.4.1 Keyring Plugin Installation ...................................................................................... 199 6.4.2 Using the keyring_file File-Based Keyring Plugin ..................................................... 201 6.4.3 Using the keyring_encrypted_file Encrypted File-Based Keyring Plugin ...................... 202 6.4.4 Using the keyring_okv KMIP Plugin .......................................................................