Skip to content

Instantly share code, notes, and snippets.

@dtest11
Last active August 21, 2021 04:39
Show Gist options
  • Save dtest11/0aa90bc0117fe0491ca1e977a847097f to your computer and use it in GitHub Desktop.
Save dtest11/0aa90bc0117fe0491ca1e977a847097f to your computer and use it in GitHub Desktop.
#posgresql

#posgresql

docker  run   --name postgres -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_USER=test -p 5432:5432 \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-e POSTGRES_DB=foo \
-v /home/code/Desktop/postgres/data:/var/lib/postgresql/data/pgdata postgres


#进入continer 创建用户
docker exec -it pg 

`  sudo -i -u postgres `或者  ` su postgres ` 切换倒psql
`psql -h localhost -d foo -U test -p 5432 ` 进入psql 控制台

创建用户
createuser --interactive

#修改密码

alter user hello with password '123456';

GRANT ALL PRIVILEGES ON DATABASE hello TO hello;
@dtest11
Copy link
Author

dtest11 commented Aug 21, 2021

test
func main() {
	data := []byte("123456")
	fmt.Printf("%x", md5.Sum(data))
	var dsn = `user=test password=mysecretpassword host=127.0.0.1 port=5432 dbname=foo`
	_, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})

	if err != nil {
		panic(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment