MySQL/MariaDB: сменить пароль пользователя

Автор: | 27/04/2016

mariadb_logoВ случае проблем вида:

$ mysql -u jira -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'jira'@'localhost' (using password: YES)

Можно сбросить пароль пользователя.

Для этого – подключаемся под root:

$ mysql -u root -p

Изменить пароль можно двумя способами:

MariaDB [(none)]> SET PASSWORD FOR 'jira'@'localhost' = PASSWORD('newpassword');
Query OK, 0 rows affected (0.04 sec)

либо:

MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE USER='jira' AND Host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Перезагружаем правила доступа:

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

Проверяем:

$ mysql -u jira -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 60
Server version: 10.0.23-MariaDB-0+deb8u1 (Debian)

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Готово.