Руководство по сбросу паролей базы данных
В повседневном управлении базами данных сброс пароля является обычной и необходимой операцией. Независимо от причин, будь то соображения безопасности, забытый пароль или что-то еще, знание способа сброса пароля базы данных имеет решающее значение для администраторов баз данных. В этой статье подробно рассматривается, как сбросить пароли баз данных MariaDB, PostgreSQL и Redis. При использовании ServBay следует учитывать, что для разных версий баз данных существуют различные настройки и пути.
Сброс пароля MariaDB
MariaDB является форком MySQL и представляет собой популярную систему управления реляционными базами данных. Следующие шаги помогут вам сбросить пароль MariaDB.
В качестве примера используется версия MariaDB 10.11
.
Процесс сброса пароля MariaDB
Остановите службу MariaDB:
bashservbayctl stop mariadb 10.11
1Запустите MariaDB в безопасном режиме:
bash/Applications/ServBay/package/mariadb/10.11/current/bin/mysqld_safe --skip-grant-tables --skip-networking &
1Войдите в MariaDB:
bash/Applications/ServBay/package/mariadb/10.11/current/bin/mysql -u root
1Сбросьте пароль:
sqlFLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
1
2
3Выйдите из MariaDB:
sqlexit;
1Остановите MariaDB, запущенную в безопасном режиме:
bashservbayctl stop mariadb 10.11
1Перезапустите службу MariaDB:
bashservbayctl start mariadb 10.11
1
Сброс пароля PostgreSQL
PostgreSQL — это мощная система управления объектно-реляционными базами данных с открытым исходным кодом. Следующие шаги помогут вам сбросить пароль PostgreSQL.
В качестве примера используется версия PostgreSQL 16
.
Процесс сброса пароля PostgreSQL
- Найдите учетную запись администратора PostgreSQL
Откройте панель управления ServBay в разделе Настройки
-Пароль базы данных
, найдите Account
для PostgreSQL.
Остановите службу PostgreSQL:
bashservbayctl stop postgresql 16
1Создайте резервную копию файла
pg_hba.conf
:bashcp /Applications/ServBay/db/postgresql/16/pg_hba.conf /Applications/ServBay/db/postgresql/16/pg_hba.conf.bak
1Отредактируйте файл
pg_hba.conf
, уберите аутентификацию по паролю:bashsed -i '' 's/scram-sha-256/trust/g' /Applications/ServBay/db/postgresql/16/pg_hba.conf
1Запустите PostgreSQL:
bashservbayctl start postgresql 16
1Войдите в командную строку
psql
:bashpsql -h /Applications/ServBay/tmp -U <пользователь, найденный на первом шаге> постгер sql # Например: psql -h /Applications/ServBay/tmp -U servbay postgresql
1
2Сбросьте пароль:
sqlALTER USER <пользователь, найденный на первом шаге> WITH PASSWORD 'new_password'; -- Например: ALTER USER servbay WITH PASSWORD 'new_password';
1
2Выйдите из
psql
:sql\q
1Остановите службу PostgreSQL:
bashservbayctl stop postgresql 16
1Восстановите файл
pg_hba.conf
:bashcp /Applications/ServBay/db/postgresql/16/pg_hba.conf.bak /Applications/ServBay/db/postgresql/16/pg_hba.conf
1Перезапустите службу PostgreSQL:
bashservbayctl start postgresql 16
1
Сброс пароля Redis
Redis — это открытый источник хранилища данных структур в памяти, используемый как база данных, кэш и брокер сообщений. Следующие шаги помогут вам сбросить пароль Redis.
Процесс сброса пароля Redis
Откройте файл конфигурации Redis:
bashvim /Applications/ServBay/package/etc/redis/redis.conf
1Найдите настройку
requirepass
и измените ее:plaintextrequirepass new_password
1Сохраните и закройте редактор.
Перезапустите службу Redis:
bashservbayctl restart redis -all
1
Заключение
Сброс пароля базы данных — это важная задача в управлении базами данных. В этой статье подробно рассматривается, как сбросить пароли баз данных MariaDB, PostgreSQL и Redis. При использовании ServBay следует учитывать, что для разных версий баз данных существуют различные настройки и пути. Следуя этим шагам, вы сможете обеспечить безопасность и доступность вашей базы данных. Независимо от причин, будь то соображения безопасности или забытый пароль, освоение этих навыков поможет вам лучше управлять системами баз данных.