Set Password Policy in Mysql 5.6

——————————————————————————————-
1) INSTALL PLUGIN loads the plugin, and also registers it in the mysql. plugins table
to cause the plugin to be loaded for each subsequent normal server startup.
——————————————————————————————-

mysql> INSTALL PLUGIN validate_password SONAME  'validate_password.so';

——————————————————————————————-
2) Edit my.cnf file & Add following 2 parameters in my.cnf
——————————————————————————————-

# vi /etc/my.cnf

[mysqld]
plugin-load=validate_password.so
validate-password=FORCE_PLUS_PERMANENT

——————————————————————————————-
3) Login Mysql & Set Following parameters as per your requirement
——————————————————————————————-

[root@maindb ~]# mysql -u root -p
Enter password:

 

mysql> SET GLOBAL validate_password_length = 8;
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password_number_count = 3;
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL validate_password_special_char_count = 3;
Query OK, 0 rows affected (0.00 sec)

——————————————————————————————-
4) Check Parameters
——————————————————————————————-

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 3      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 3      |
+--------------------------------------+--------+
6 rows in set (0.00 sec)

——————————————————————————————-
5) Test With Following Password
——————————————————————————————-

select password('test');
select password('Test@12345');
select password('Test@123456789');
select password('Test@!#123456789');
[root@maindb ~]# mysql -u root -p
Enter password:

mysql> GRANT ALL PRIVILEGES ON mastercard.* TO 'mastercard'@'localhost' IDENTIFIED BY 'MasterCard@12345';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

mysql> GRANT ALL PRIVILEGES ON mastercard.* TO 'mastercard'@'localhost' IDENTIFIED BY 'MasterCard@!#12345';
Query OK, 0 rows affected (0.00 sec)

This entry was posted in Linux, MySQL and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *