【问题标题】:How to get started with PostgreSQL similar to MySQL如何开始使用类似于 MySQL 的 PostgreSQL
【发布时间】:2012-10-05 02:18:20
【问题描述】:

我不知道:

  1. 只需登录到 postgreSQL
  2. 创建数据库
  3. 添加表格
  4. 插入记录
  5. 删除、更新等

这些事情通常使用 mysql 非常容易。有人可以帮我设置以下 postgresql 的替代方案吗

a) Reset 默认密码——非常简洁的描述, 我没有发现 PostgreSQL 的清晰程度相同 (任何文档链接都非常感谢)

b) 我们知道 mysql 的超级用户是“root”,而 PostgreSQL 也是如此

c) 从命令行如何(PostgreSQL 的?):

 mysql -uroot -proot  
   create database testdb; 
   use testdb;
   create table test(id int(11) auto_increment, name varchar(20), primary key(id));
   insert into test(name) values("testing one"),("testing two"),("testing three"),("testing four");
   select * from test;
   update test set name=concat(name,now()) where id =3;
   delete from test where id =4;
   drop table if exists test;
   drop database if exists testdb;

编辑 MAC 操作系统 # 默认密码重置

sudo mate /Library/PostgreSQL/9.2/data/pg_hba.conf

替换(md5 信任)

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

保存

执行了 Reload Configuration.app

 login to postgresql without password : 
  $ psql -U postgres
  postgres# ALTER USER postgres WITH PASSWORD 'new password';
  \q  

-还原 pg_hba.conf 中的所有更改(用 md5 替换 trust)并保存

-重新加载配置

现在我可以使用新密码登录 postgresql

psql -U postgres

Password for user postgres:[my new password]

【问题讨论】:

  • @BurhanKhalid 非常感谢,但仍然无法登录到 postgreSQL :(
  • 你可以从终端登录为` psql -d postgres_db_name -U postgres`
  • @Thanga,我不知道默认用户和密码,这就是我试图直接弄清楚的

标签: mysql postgresql-9.2


【解决方案1】:

登录:

psql -d postgres_dbname -U postgres

创建数据库:

create database  testuser;

\c testuser;  /*use testuse as mysql*/

创建表:

create table employee (Name char(20));

插入:

 insert into employee VALUES ('XAS');

Update Link

Delete Link

Reset Password :See Here & See Here Too

【讨论】:

  • 请用重置链接更新你的答案,我会接受你的答案,谢谢你的帮助
【解决方案2】:

只需登录到 postgreSQL

psql -U postgres -W template1
-U = username
postgres is root 
-W = ask for password
tempalte1 = default database

创建数据库

-- Create the database from within postgresql
create database my_database_name
-- Connect to the database
\c my_database_name

-- Create the database without logging in
createdb -U postgres -W my_database_name
  1. 添加表格
  2. 插入记录
  3. 删除、更新等

以上从 3 到 5 都和 MySQL 一样

对于重置 postgres 忘记密码 this link 是一个很好的参考。

【讨论】:

  • $ psql -U postgres -W template1 用户 postgres 的密码:psql: FATAL: 用户“postgres”的密码验证失败
  • 你知道你的 postgres 密码吗?你有密码吗?
  • 谢谢,psql -U postgres -W template1 提示我Password for user postgres: 我不知道并且需要设置(我在 MAC OS 上,我不知道这是否会影响任何事情)
  • 这就是我需要的,我需要设置ROOT or superuser password
  • 然后点击我帖子中的链接;)
【解决方案3】:

postgresql 是一个与 mysql 完全不同的系统;所以不要假设事情会像mysql。它们是完全不同的动物;您的某些 SQL 语句可能不起作用,尤其是在您使用 MySQL 专有命令时。

  1. 要登录到 postgresql,请使用 psql command shell
  2. CREATE DATABASE
  3. CREATE TABLE
  4. INSERT
  5. 对于所有其他基本 SQL 命令,请考虑通过 tutorial

用户访问控制在 postgresql 中是更细粒度和详细的。有用户和角色。用户只是具有登录能力的角色(如 MySQL),但在 postgresql 中,您可以拥有无​​法登录的角色(帐户)。

角色的访问权限在pg_hba.conf 中定义。这个文件定义了一个角色是否可以登录,他们通过什么方式进行身份验证,他们可以从哪里登录以及他们可以访问什么数据库。

ALTER USER 用于重置凭据。

postgresql 的“root 用户”通常是postgres;这是在安装过程中创建的系统用户。对于 Windows,二进制安装程序会询问您是否也想以此用户身份启动服务。

【讨论】:

  • 你能帮我登录 postgreSQL 吗?还是重置root密码?谢谢你的描述
  • 登录su -(切换到root),然后su postgres,然后输入psql
  • sudo postgres psql Password: PostgreSQL 服务器的“root”执行是不允许的。必须在非特权用户 ID 下启动服务器,以防止可能的系统安全受损。有关如何正确启动服务器的更多信息,请参阅文档。
  • @Hector @sakunzai - 您需要先确保服务器正在运行,或者如果您要连接到远程服务器,请使用 -h 标识它
【解决方案4】:

请看看这个PostgreSQL error 'Could not connect to server: No such file or directory'

尝试安装postgresApp,这解决了我的问题,和你的一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    相关资源
    最近更新 更多