gpt4 book ai didi

ruby-on-rails - 如何在 Ubuntu 中连接 PostgreSQL

转载 作者:行者123 更新时间:2023-12-04 19:17:26 25 4
gpt4 key购买 nike

我通过以下命令在我的 Ubuntu 服务器上安装了 PostgreSQL 数据库

sudo apt-get install postgresql postgresql-contrib

但是在这里我不知道如何连接这个 PostgreSQL 数据库以及如何设置它的用户名、密码、主机和端口。因为我要在我的 Rails 项目中使用这个数据库,所以这些东西是必需的。请帮我设置这个数据库.

database.yml:


default: &default
adapter: postgresql
encoding: unicode
database: 100salons
username: sallon
password: 12345
host: 10.25.25.100
port: 5432
pool: 5

development:
<<: *default
database: 100salons_dev
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: 100salons

# The password associated with the postgres role (username).
#password:

# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost

# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432

# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public

# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: 100salons_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: 100salons_prod

最佳答案

Postgresql 有不同的命令来创建不同版本的密码和用户名。

对于 9.3:

对于创建用户类型命令:

sudo su – postgres ## This will take you to postgres user

createuser ## To create new user

上面的命令提示符如下:
Enter name of role to add: newuser
Shall the new role be a superuser? (y/n) y

要为新创建的用户类型创建密码:
createuser --pwprompt

对于 9.4:

输入简单的命令:
createuser -P -s -e joe ## joe is username here

这将输出如下:
 Enter password for new role: xyzzy
Enter it again: xyzzy
CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;

你完成了。

对于 9.4 文档 here . 9.3 here

关于ruby-on-rails - 如何在 Ubuntu 中连接 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32476039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com