《Linux命令行与shell脚本编程大全》-使用数据库下载

[plain] mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON test.* TO test_user IDENTIFIED by 'pwd';  Query OK, 0 rows affected (0.00 sec)  之后就可以使用新账户登录了[plain] $ mysql test -u test_user -p  Enter password:   Welcome to the MySQL monitor.  Commands end with ; or g.  Your MySQL connection id is 59  Server version: 5.1.72-0ubuntu0.10.04.1 (Ubuntu)    Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.    Oracle is a registered trademark of Oracle Corporation and/or its  affiliates. Other names may be trademarks of their respective  owners.    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.   PostgreSQL数据库PostgreSQL命令行界面psql命令行参数简写名称 完整名称 描述-a –echo-all 在输出中显示脚本文件中执行的所有SQL行-A –no-align 将输出格式设为非对齐模式,数据不显示或格式化的表-c –command 执行指定的SQL语句并退出-d –dbname 指定要连接的数据库-e –echo-queries 将所有的查询输出到屏幕上-E –echo-hidden 将隐藏的psql元命令输出到屏幕上-f –file 执行指定文件中的SQL命令并退出-F –field-separator 指定在非对齐模式中分开列表数据的字符。默认是逗号-h –host 指定远程PostgreSQL服务器的IP地址或主机名-l –list 显示服务器上已有的数据库列表并退出-o –output 将查询输出重定向到指定文件中-p –post 指定要连接的PostgreSQL服务器的TCP端口-P –pset 将表打印选项设为指定的值-q –quiet 安静模式,不会显示输出消息-R –record-separator 将指定字符做为数据行分隔符。默认为换行符-s –single-step 在每个SQL查询后 提示继续还是退出-S –single-line 指定回车键而不是分号为一个SQL查询的结束-t –tuples-only 在表输出中禁用列的头部和尾部-T –table-attr 在HTML模式时使用指定的HTML表标签-U –username 使用指定的用户名连接PostgreSQL服务器-v –variable 将指定变量设成指定值-V –version 显示psql版本号并退出-W –password 强制命令提示符-x –expanded 使能扩展表输出以显示数据行的额外信息-X –nopsqlrc 不要运行psql启动文件-? –help 显示psql命令行帮助信息并退出PostgreSQL管理员账户为postgres,而不是root如果知识兔当前Linux登录账户不是postgres,那么需要使用sudo来以postgres账户运行psql[plain] $ sudo -u postgres psql  [sudo] password for su1216:   psql (8.4.17)  Type “help” for help.    postgres=#  提示符#表示已经做为管理员登录psql。psql使用两种不同类型的命令:1.Postgre元命令2.标准SQL语句 Postgre元命令可以方便的获取数据库环境确切信息,还具有psql会话的set功能。元命令用反斜线标示。常用的元命令:l:列出已有数据库c:连接到数据库dt:列出数据库中的表du列出Postgre的用户z:列出表的权限?:列出所有可用元命令h:列出所有可用SQL命令q:退出数据库[plain] postgres=# l                                   List of databases     Name    |  Owner   | Encoding | Collation |    Ctype    |   Access privileges     ———–+———-+———-+———–+————-+———————–   postgres  | postgres | UTF8     | C         | zh_CN.UTF-8 |    template0 | postgres | UTF8     | C         | zh_CN.UTF-8 | =c/postgres                                                             : postgres=CTc/postgres   template1 | postgres | UTF8     | C         | zh_CN.UTF-8 | =c/postgres                                                             : postgres=CTc/postgres  (3 rows)  创建PostgreSQL数据库对象CREATE DATABASE +库名[plain] postgres=# CREATE DATABASE test;  CREATE DATABASE  postgres=# l                                   List of databases     Name    |  Owner   | Encoding | Collation |    Ctype    |   Access privileges     ———–+———-+———-+———–+————-+———————–   postgres  | postgres | UTF8     | C         | zh_CN.UTF-8 |    template0 | postgres | UTF8     | C         | zh_CN.UTF-8 | =c/postgres                                                             : postgres=CTc/postgres   template1 | postgres | UTF8     | C         | zh_CN.UTF-8 | =c/postgres                                                             : postgres=CTc/postgres   test      | postgres | UTF8     | C         | zh_CN.UTF-8 |   (4 rows)    postgres=# c test  psql (8.4.17)  You are now connected to database “test”.  test=#  连接到test数据库上的时候,psql的提示符变了,显示的是连接的数据库名称说明:PostgreSQL在数据库增加了一个控制层,称为模式(schema)。数据库可以有多个模式,每个模式包含多个表。默认情况下,每个数据库都有一个称为public的模式。上面的例子中使用的就是public模式。PostgreSQL中用户账户称为登录角色(Login Role)。PostgreSQL会将登录角色和Linux系统用户账户匹配。所以有两种常用方法来创建登录角色来运行访问PostgreSQL数据库的shell脚本:1.创建一个和PostgreSQL登录角色对应的特殊Linux账户来运行所有的shell脚本2.为每个需要运行shell脚本来访问数据库的Linux用户账户创建PostgreSQL账户CREATE ROLE +名称[plain] test=# CREATE ROLE su login;  CREATE ROLE  test=#   这样就建立了一个角色,如果知识兔不使用login参数的话,则不允许登录到PostgreSQL服务器,但可以被授予一些权限。这种角色类型称为组角色(group role)。

本文来自系统大全为您分享如需转载请注明!推荐win10下载

下载仅供下载体验和测试学习,不得商用和正当使用。

下载体验

请输入密码查看下载!

如何免费获取密码?

点击下载

评论