隨筆-124  評論-194  文章-0  trackbacks-0

          最近因為用HYPERIC產品,裝了一下Postgres數據庫,下面簡說下在WINDOWS下安裝的情況。

           

          下載那個直接解壓版,解壓

          "$PG"目錄下創建一個rootpass.txt文件,內容為數據庫的超級用戶密碼。可以填個“p”,方便后面登陸。
          準備工作到此結束,下面的步驟以管理員身份執行。

          移動DLL文件[8.1.5及以上版本不需要這一步驟]

          cd $PG

          move /y lib\comerr32.dll   bin\

          move /y lib\krb5_32.dll    bin\

          move /y lib\libeay32.dll   bin\

          move /y lib\libiconv-2.dll bin\

          move /y lib\libintl-2.dll  bin\

          move /y lib\libpq.dll      bin\

          move /y lib\pthreadGC2.dll bin\

          move /y lib\ssleay32.dll   bin\

          添加新的postgres用戶,并將密碼設為:p

          net user postgres p /ADD /EXPIRES:NEVER /PASSWORDCHG:NO

          net localgroup users postgres /delete

          創建data目錄并設置訪問權限:

          md data

          cacls .    /T /E /P postgres:R

          cacls data /T /E /P postgres:C

          POSTGRES不支持管理員狀態運行,我們用RUNAS來做,如果失敗,可以查下是不是有個SECOND LOGON服務是不是停了,啟動一下即可。

          初始化PostgreSQL數據庫,切換用戶時需要手動輸入postgres用戶的密碼:p

          runas /noprofile /env /user:postgres "bin\initdb -D data -E EUC_CN --locale=\"Chinese_People's Republic of China.936\" -A md5 -U postgres --pwfile=rootpass.txt"

          這樣就安裝好了。需要說明的是數據庫默認編碼為:EUC_CN(GB2312),區域設置為:zh_CN.GBK,數據庫超級用戶名為:root,密碼為rootpass.txt文件內容,使用md5認證。

          以后可以使用:

          runas /noprofile /env /user:postgres "bin\pg_ctl start -w -D data"

          啟動PG,使用:

          runas /noprofile /env /user:postgres "bin\pg_ctl stop -D data -m smart"

          關閉PG

           

          用登錄:

          runas /noprofile /env /user:postgres "bin\psql -U postgres"

           

          登錄后就可以創用戶,創數據庫。

           

          一些命令對比:

           

          PostgreSQLMySQL命令比較

           

          PostgreSQL

          MySQL

          服務啟動:
              1)#service postgresql start
              2)#/etc/init.d/postgresql start
              3)#su – postgresql
                $pg_ctl start
          PostgreSQL的進程號:12101207

          服務啟動:
              1)#service mysqld start
              2)#/etc/init.d/mysqld start
              3)#safe_mysqld&

           

          MySQL的進程號為1663

          第一次進入數據庫:
              #su – postgres
              $createdb  (建名為postgres的數據庫)
              $psql 

          第一次進入數據庫:

               #mysql
               mysql>    (出現這個提示符說明成功)

          創建用戶:(用戶Ajian,密碼:123)
              #su – postgres

          $psql

          =#create user ajian with password ‘123’

          創建用戶:(用戶Ajian,密碼:123)
               #grant all privileges on *.* to ajian@"%" identified by "123"

           (注意:同還可以分配權限,這里是ALL)

          創建數據庫(My)

              #su – postgres

          $psql

          =#create database My with owner = ajian template = template1 encoding=’UNICODE’;

          創建數據庫(My)

               1)#mysql

               Mysql>create database My;

                2)#mysqladmin create My

          查看用戶和數據庫:

              #su – postgres

          $psql

              =#\l         (查看數據庫)
              =#\du        (查看用戶)

          查看用戶和數據庫:

              1)#mysql

               Mysql>show databases;   (看數據庫)

                2)#mysqlshow

          新建用戶登錄:

          (首先修改配置文件)

          # vi /var/lib/pgsql/data/pg_hba.conf(在最后加)

          host all all 127.0.0.1 255.255.255.255 md5

          再重啟服務:#service postgresql restart

          登錄:#psql –h 127.0.0.1 –U ajian My

          Password:

          新建用戶登錄:

               1)#mysql –u ajian –p  (帶口令登錄)

               2)#mysql

                Mysql>use My;

               (不帶口令登錄一般用于本機)

          創建表(employee)

          =#create table employee(

          (#employee_id int primary key,

          (#name char(8),

          (#sex char(2));

          創建表:

           >create table employee(

          ->employee_id int primary key,

          ->name char(8),

          ->sex char(2));

          查看表:

              =#\dt

          查看表:

              >show tables;

          查看表的結構:

              =#\d employee

          查看表的結構:

              >sescribe employee;

          向表中添加數據:

             =#insert into employee values

            -#(‘1’,’zhang’,’F’);

          -#(‘2’,’chen’,’M’,);

          向表中添加數據:

          >insert into employee values

            ->(‘1’,’zhang’,’F’);

          ->(‘2’,’chen’,’M’,);

          查看表的數據:

            =#select * from emlpoyee

          查看表的數據:

          >select * from emlpoyee;

          創建索引(IN_employee)

          =#create index IN_employee on employee(name);

          查看索引:

          =#\di

          刪除索引:

          =#drop index IN_employee on employee;

          重建索引:

          =#reindex table employee;(重建employee所有的)

          =#reindex index IN_employee;(重建指定的)

          創建索引(IN_employee)

          1)>create index IN_employee on employee(name);

          2)>alter table employee add index IN_employee(name);

          查看索引:

          >show index from employee;

          刪除索引:

          1)>drop index IN_employee on employee;

          2)>alter table emlpoyee drop index IN_employee;

          刪除表:

             =#drop table employee;

          刪除表:

             >drop table employee;

          刪除數據庫:(注意命令前面的標志)

             1)=#drop database ajian;

             2)$dropdb ajian

          刪除數據庫:(注意命令前面的標志)

             1>drop database ajian;

             2)#mysqladmin drop ajian

           

          posted on 2007-08-12 15:56 我愛佳娃 閱讀(5776) 評論(0)  編輯  收藏 所屬分類: DB相關
          主站蜘蛛池模板: 营口市| 新乡县| 天等县| 沾益县| 宁明县| 绥棱县| 贵州省| 甘孜县| 微博| 嘉鱼县| 甘泉县| 和硕县| 正定县| 如东县| 巨野县| 兰溪市| 盖州市| 望都县| 喀喇沁旗| 东海县| 长兴县| 夏河县| 宁明县| 沧州市| 棋牌| 崇州市| 长治县| 长顺县| 顺平县| 凤阳县| 桐梓县| 青海省| 孙吴县| 龙山县| 禄丰县| 青河县| 托里县| 临潭县| 乌苏市| 凤山市| 稻城县|