如何开始使用类似于MySQL的PostgreSQL

时间:2012-10-15 05:55:13

标签: mysql postgresql-9.2

我没有得到一个线索:

  1. 只需登录postgreSQL
  2. 即可
  3. 创建数据库
  4. 添加表格
  5. 插入记录
  6. 删除,更新等
  7. 使用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 OS  #默认密码重置

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

    替换(md5 with trust)

    # "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]

4 个答案:

答案 0 :(得分:2)

登录:

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

答案 1 :(得分:1)

只需登录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. 删除,更新等
  4. 以上所有3到5就像在MySQL中一样

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

答案 2 :(得分:1)

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

  1. 要登录postgresql,请使用psql command shell
  2. CREATE DATABASE
  3. CREATE TABLE
  4. INSERT
  5. 对于所有其他基本SQL命令,请考虑浏览tutorial
  6. 用户访问控制在postgresql中更精细,更详细。有用户和角色。用户只是一个具有登录能力的角色(如MySQL),但在postgresql中,您可以拥有无​​法登录的角色(帐户)。

    pg_hba.conf中定义了角色的访问权限。此文件定义角色是否可以登录,通过何种方式进行身份验证,登录的位置以及他们可以访问的数据库。

    ALTER USER用于重置凭据。

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

答案 3 :(得分:0)

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

尝试安装postgresApp,这解决了我的问题,这与你的问题相同。