This program enables you to improve the security of your MySQL installation in the following ways:
You can set a password for
rootaccounts.You can remove
rootaccounts that are accessible from outside the local host.You can remove anonymous-user accounts.
You can remove the
testdatabase (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start withtest_.
mysql_secure_installation helps you implement security recommendations similar to those described at Section 2.10.4, “Securing the Initial MySQL Accounts”.
As of MySQL 5.7.2, mysql_secure_installation is an executable binary available on all platforms. Before 5.7.2, it was a script available for Unix and Unix-like systems.
Normal usage is to connect to the local MySQL server; invoke mysql_secure_installation without arguments:
shell> mysql_secure_installationWhen executed, mysql_secure_installation prompts you to determine which actions to perform.
As of MySQL 5.7.2, mysql_secure_installation supports these additional features:
The
validate_passwordplugin can be used for password strength checking. If the plugin is not installed, mysql_secure_installation prompts the user whether to install it. Any passwords entered later are checked using the plugin if it is enabled.Most of the usual MySQL client options such as
--hostand--portcan be used on the command line and in option files. For example, to connect to the local server over IPv6 using port 3307, use this command:shell> mysql_secure_installation --host=::1 --port=3307
mysql_secure_installation supports the
following options, which can be specified on the command line or
in the [mysql_secure_installation] and
[client] groups of an option file. For
information about option files used by MySQL programs, see
Section 4.2.6, “Using Option Files”.
Table 4.7 mysql_secure_installation
Options
| Format | Description | Introduced |
|---|---|---|
| --defaults-extra-file | Read named option file in addition to usual option files | 5.7.2 |
| --defaults-file | Read only named option file | 5.7.2 |
| --defaults-group-suffix | Option group suffix value | 5.7.2 |
| --help | Display help message and exit | 5.7.2 |
| --host | Host to connect to (IP address or host name) | 5.7.2 |
| --no-defaults | Read no option files | 5.7.2 |
| --password | Accepted but always ignored. Whenever mysql_secure_installation is invoked, the user is prompted for a password, regardless. | 5.7.2 |
| --port | TCP/IP port number for connection | 5.7.2 |
| --print-defaults | Print default options | 5.7.2 |
| --protocol | Connection protocol to use | 5.7.2 |
| --socket | For connections to localhost, the Unix socket file to use | 5.7.2 |
| --ssl | Enable encrypted connection | 5.7.2 |
| --ssl-ca | File that contains list of trusted SSL Certificate Authorities | 5.7.2 |
| --ssl-capath | Directory that contains trusted SSL Certificate Authority certificate files | 5.7.2 |
| --ssl-cert | File that contains X509 certificate | 5.7.2 |
| --ssl-cipher | List of permitted ciphers for connection encryption | 5.7.2 |
| --ssl-crl | File that contains certificate revocation lists | 5.7.2 |
| --ssl-crlpath | Directory that contains certificate revocation list files | 5.7.2 |
| --ssl-key | File that contains X509 key | 5.7.2 |
| --ssl-verify-server-cert | Verify host name against server certificate Common Name identity | 5.7.2 |
| --tls-version | Protocols permitted for encrypted connections | 5.7.10 |
| --use-default | Execute with no user interactivity | 5.7.4 |
| --user | MySQL user name to use when connecting to server | 5.7.2 |
--help,-?Display a help message and exit.
--defaults-extra-file=file_nameRead this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, an error occurs.
file_nameis interpreted relative to the current directory if given as a relative path name rather than a full path name.Use only the given option file. If the file does not exist or is otherwise inaccessible, an error occurs.
file_nameis interpreted relative to the current directory if given as a relative path name rather than a full path name.Read not only the usual option groups, but also groups with the usual names and a suffix of
str. For example, mysql_secure_installation normally reads the[client]and[mysql_secure_installation]groups. If the--defaults-group-suffix=_otheroption is given, mysql_secure_installation also reads the[client_other]and[mysql_secure_installation_other]groups.--host=,host_name-hhost_nameConnect to the MySQL server on the given host.
Do not read any option files. If program startup fails due to reading unknown options from an option file,
--no-defaultscan be used to prevent them from being read.The exception is that the
.mylogin.cnffile, if it exists, is read in all cases. This permits passwords to be specified in a safer way than on the command line even when--no-defaultsis used. (.mylogin.cnfis created by the mysql_config_editor utility. See Section 4.6.6, “mysql_config_editor — MySQL Configuration Utility”.)--password=,password-ppasswordThis option is accepted but ignored. Whether or not this option is used, mysql_secure_installation always prompts the user for a password.
--port=,port_num-Pport_numThe TCP/IP port number to use for the connection.
Print the program name and all options that it gets from option files.
--protocol={TCP|SOCKET|PIPE|MEMORY}The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see Section 4.2.2, “Connecting to the MySQL Server”.
--socket=,path-SpathFor connections to
localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.Options that begin with
--sslspecify whether to connect to the server using SSL and indicate where to find SSL keys and certificates. See Section 6.4.2, “Command Options for Encrypted Connections”.The protocols permitted by the client for encrypted connections. The value is a comma-separated list containing one or more protocol names. The protocols that can be named for this option depend on the SSL library used to compile MySQL. For details, see Section 6.4.6, “Encrypted Connection Protocols and Ciphers”.
This option was added in MySQL 5.7.10.
Execute noninteractively. This option can be used for unattended installation operations. This option was added in MySQL 5.7.4.
--user=,user_name-uuser_nameThe MySQL user name to use when connecting to the server.
http://howtolamp.com/lamp/mysql/5.6/securing/