Kết nối vào database postgresql đang chạy trên docker container
24/08/2021 239 lượt xem1. Kết nối vào Container
Giả sử cấu hình trong file docker-compose.yml như vậy
ports:
- "5433:5432"
environment:
- POSTGRES_PASSWORD=123
- POSTGRES_USER=postgreuser
- POSTGRES_DB=postgres
restart: always
$ docker exec -it container_name bash
2. Kết nối tới Database
*** Vào Postgres
$ su postgres
$ psql -p port_postgresql -h host(Ip vps, localhost, 0.0.0.0) -d postgres -U user_name
**Ex: psql -p 5433 -h 116.118.48.111 -d postgres -U postgreuser
$ Nhap_database_pass
+ HOẶC KẾT NỐI THẲNG NẾU BẠN ĐANG Ở TÀI KHOẢN ROOT
+ SAU KHI RUN LỆNH NÀY "docker exec -it container_name bash"
$ psql -d postgres -U user_name
*** Kết nối tới Database
$postgres \connect database-name
3. Thoát ra Container
*** Thoát khỏi database
postgres=# \q
*** Thoát khỏi Postgres
$ exit
***Thoát khỏi Container
$ exit
4. Các lệnh thao tác với Postgresql cơ bản
\dt : list all table in odoo db
Q : Nhấn phím q để thoát
\q : Thoát chế độ thao tác db
Exit : Thoát khỏi Postgress SQL
\d+ table_name: show structure table
Delete from table_name Condition; Delete row in table
Update table_name set column=new_value where Condition; Update table set value
Update table_name set column=’new_text’ where Condition; Update table set text
5. Đổi mật khẩu Admin Odoo
** Sau khi kết nối vào database chạy lệnh sau
$ UPDATE res_users SET password_crypt='mk_moi' WHERE id=1;
*** Hoặc
$ UPDATE res_users SET password='mk_moi' WHERE id=1;
*** Hoặc chạy cả 2 lệnh trên
