Guide to Reset Database Passwords
In the routine management of databases, resetting the database password is a common and necessary task. Whether for security reasons, forgotten passwords, or other causes, knowing how to reset database passwords is crucial for database administrators. This article provides a detailed guide on how to reset database passwords for MySQL, MariaDB, PostgreSQL, and Redis. Note that when using ServBay, different versions of the databases have different configurations and paths.
Reset MySQL/MariaDB Password
TIP
The steps to reset MySQL and MariaDB are identical.
MySQL and MariaDB are popular relational database management systems. The following steps will guide you on how to reset the password for MySQL/MariaDB.
Below is an example using MariaDB 11.3
.
Reset MariaDB Root Password Using GUI
Open ServBay, select Database
- MariaDB
- MariaDB 11.3
from the left navigation. On the right page, find the Password
input box. To the right of this box, there is an icon with a small lock. Click it to prompt whether you want to reset the root user password. Click Confirm.
The root password will then be reset to the default ServBay.dev
.
Reset MariaDB Password Using Command Line
Stop MariaDB Service:
bashservbayctl stop mariadb 11.3
1Start MariaDB in Safe Mode:
bash/Applications/ServBay/package/mariadb/11.3/current/bin/mysqld_safe --skip-grant-tables --skip-networking &
1Log in to MariaDB:
bash/Applications/ServBay/package/mariadb/11.3/current/bin/mysql -u root
1Reset Password:
sqlFLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
1
2
3Exit MariaDB:
sqlexit;
1Stop MariaDB in Safe Mode:
bashservbayctl stop mariadb 11.3
1Restart MariaDB Service:
bashservbayctl start mariadb 11.3
1
Reset PostgreSQL Password
PostgreSQL is a powerful open-source object-relational database system. The following steps will guide you on how to reset the PostgreSQL password.
Below is an example using PostgreSQL 16
.
Process to Reset PostgreSQL Password
- Locate PostgreSQL Admin Account
Open the ServBay management panel and navigate to Database
- PostgreSQL
- PostgreSQL 16
to find the PostgreSQL Account
.
Stop PostgreSQL Service:
bashservbayctl stop postgresql 16
1Backup
pg_hba.conf
File:bashcp /Applications/ServBay/db/postgresql/16/pg_hba.conf /Applications/ServBay/db/postgresql/16/pg_hba.conf.bak
1Edit the
pg_hba.conf
File to remove password authentication:bashsed -i '' 's/scram-sha-256/trust/g' /Applications/ServBay/db/postgresql/16/pg_hba.conf
1Start PostgreSQL:
bashservbayctl start postgresql 16
1Enter
psql
Command Line:bashpsql -h /Applications/ServBay/tmp -U <user obtained from step one> postgres # For example: psql -h /Applications/ServBay/tmp -U servbay postgres
1
2Reset Password:
sqlALTER USER <user obtained from step one> WITH PASSWORD 'new_password'; -- For example: ALTER USER servbay WITH PASSWORD 'new_password';
1
2Exit
psql
:sql\q
1Stop PostgreSQL Service:
bashservbayctl stop postgresql 16
1Restore
pg_hba.conf
File:bashcp /Applications/ServBay/db/postgresql/16/pg_hba.conf.bak /Applications/ServBay/db/postgresql/16/pg_hba.conf
1Restart PostgreSQL Service:
bashservbayctl start postgresql 16
1
Reset Redis Password
Redis is an open-source, in-memory data structure store, used as a database, cache, and message broker. The following steps guide you on how to reset the Redis password.
Reset Redis Password Using GUI
Open the ServBay management panel and navigate to Database
- NoSQL
- Redis
. Enter a new password in the password input box below, and then click Save
.
Edit redis.conf
for Redis Password Reset
Open Redis Configuration File:
bashvim /Applications/ServBay/package/etc/redis/redis.conf
1Find and Modify the
requirepass
Directive:plaintextrequirepass new_password
1Save and Exit the Editor.
Restart Redis Service:
bashservbayctl restart redis -all
1
Summary
Resetting the database password is a critical task in database management. This article offers a detailed guide on how to reset database passwords for MySQL, MariaDB, PostgreSQL, and Redis. When using ServBay, note that different database versions have different configurations and paths. By following these steps, you can ensure the security and accessibility of the database. Whether for security reasons or due to forgotten passwords, mastering these skills will help you better manage your database systems.