Hướng Dẫn Đặt Lại Mật Khẩu Cơ Sở Dữ Liệu
Trong quản lý hàng ngày của cơ sở dữ liệu, đặt lại mật khẩu là một thao tác thường gặp và cần thiết. Cho dù vì lý do an toàn, quên mật khẩu, hay các nguyên nhân khác, việc hiểu cách đặt lại mật khẩu cơ sở dữ liệu là rất quan trọng đối với quản trị viên cơ sở dữ liệu. Bài viết này sẽ giới thiệu chi tiết cách đặt lại mật khẩu MariaDB, PostgreSQL và Redis. Khi sử dụng ServBay, cần chú ý rằng các phiên bản khác nhau của cơ sở dữ liệu có các cấu hình và đường dẫn khác nhau.
Đặt Lại Mật Khẩu MariaDB
MariaDB là một nhánh của MySQL và là một hệ quản trị cơ sở dữ liệu quan hệ phổ biến. Các bước sau sẽ hướng dẫn bạn cách đặt lại mật khẩu MariaDB.
Sẽ lấy ví dụ với phiên bản MariaDB 10.11
Quy trình đặt lại mật khẩu MariaDB
Dừng dịch vụ MariaDB:
bashservbayctl stop mariadb 10.11
1Khởi động MariaDB ở chế độ an toàn:
bash/Applications/ServBay/package/mariadb/10.11/current/bin/mysqld_safe --skip-grant-tables --skip-networking &
1Đăng nhập vào MariaDB:
bash/Applications/ServBay/package/mariadb/10.11/current/bin/mysql -u root
1Đặt lại mật khẩu:
sqlFLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
1
2
3Thoát MariaDB:
sqlexit;
1Dừng dịch vụ MariaDB ở chế độ an toàn:
bashservbayctl stop mariadb 10.11
1Khởi động lại dịch vụ MariaDB:
bashservbayctl start mariadb 10.11
1
Đặt Lại Mật Khẩu PostgreSQL
PostgreSQL là một hệ quản trị cơ sở dữ liệu quan hệ đối tượng nguồn mở mạnh mẽ. Các bước sau sẽ hướng dẫn bạn cách đặt lại mật khẩu PostgreSQL.
Sẽ lấy ví dụ với phiên bản PostgreSQL 16
Quy trình đặt lại mật khẩu PostgreSQL
- Tìm tài khoản quản trị PostgreSQL
Mở bảng điều khiển quản lý ServBay và vào Cài đặt
- Mật khẩu cơ sở dữ liệu
, tìm Account
của PostgreSQL
Dừng dịch vụ PostgreSQL:
bashservbayctl stop postgresql 16
1Sao lưu tệp
pg_hba.conf
:bashcp /Applications/ServBay/db/postgresql/16/pg_hba.conf /Applications/ServBay/db/postgresql/16/pg_hba.conf.bak
1Chỉnh sửa tệp
pg_hba.conf
để loại bỏ xác thực mật khẩu:bashsed -i '' 's/scram-sha-256/trust/g' /Applications/ServBay/db/postgresql/16/pg_hba.conf
1Khởi động PostgreSQL:
bashservbayctl start postgresql 16
1Truy cập dòng lệnh
psql
:bashpsql -h /Applications/ServBay/tmp -U <tài khoản từ bước đầu tiên> postgres # Ví dụ: psql -h /Applications/ServBay/tmp -U servbay postgres
1
2Đặt lại mật khẩu:
sqlALTER USER <tài khoản từ bước đầu tiên> WITH PASSWORD 'new_password'; -- Ví dụ: ALTER USER servbay WITH PASSWORD 'new_password';
1
2Thoát
psql
:sql\q
1Dừng dịch vụ PostgreSQL:
bashservbayctl stop postgresql 16
1Khôi phục tệp
pg_hba.conf
:bashcp /Applications/ServBay/db/postgresql/16/pg_hba.conf.bak /Applications/ServBay/db/postgresql/16/pg_hba.conf
1Khởi động lại dịch vụ PostgreSQL:
bashservbayctl start postgresql 16
1
Đặt Lại Mật Khẩu Redis
Redis là một bộ lưu trữ cấu trúc dữ liệu trong bộ nhớ mã nguồn mở, sử dụng làm cơ sở dữ liệu, bộ đệm và trình xử lý thông báo. Các bước sau sẽ hướng dẫn bạn cách đặt lại mật khẩu Redis.
Quy trình đặt lại mật khẩu Redis
Mở tệp cấu hình Redis:
bashvim /Applications/ServBay/package/etc/redis/redis.conf
1Tìm và chỉnh sửa mục cấu hình
requirepass
:plaintextrequirepass new_password
1Lưu và thoát trình chỉnh sửa.
Khởi động lại dịch vụ Redis:
bashservbayctl restart redis -all
1
Tổng Kết
Đặt lại mật khẩu cơ sở dữ liệu là một nhiệm vụ quan trọng trong quản lý cơ sở dữ liệu. Bài viết này đã giới thiệu chi tiết cách đặt lại mật khẩu của MariaDB, PostgreSQL và Redis. Khi sử dụng ServBay, cần chú ý rằng các phiên bản khác nhau của cơ sở dữ liệu có các cấu hình và đường dẫn khác nhau. Bằng cách tuân theo các bước này, bạn có thể đảm bảo tính an toàn và khả năng truy cập của cơ sở dữ liệu. Dù vì lý do an toàn hay quên mật khẩu, nắm vững các kỹ năng này sẽ giúp bạn quản lý hệ thống cơ sở dữ liệu tốt hơn.