postgresql 运行sql文件
方法一:
[postgres@node01 ~]$ psql -Upostgres
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows) postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# \i /stage/company.sql
DROP TABLE
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
test=# select * from company;
id | name | age | address | salary
----+-------+-----+----------------------------------------------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
(7 rows) 方法二:
[postgres@node01 ~]$ psql -Upostgres -d test0 -f /stage/company.sql
DROP TABLE
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
INSERT 0 1
[postgres@node01 ~]$ psql -Upostgres
psql.bin (10.14)
Type "help" for help. postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
test0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(5 rows) postgres=# \c test0
You are now connected to database "test0" as user "postgres".
test0=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | company | table | postgres
(1 row) test0=# select * from company;
id | name | age | address | salary
----+-------+-----+----------------------------------------------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
(7 rows)
postgresql 运行sql文件的更多相关文章
- Mysql运行SQL文件 错误Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
问题描述 想从服务器上DOWN下数据库.操作:先把数据库转存为SQL文件,然后在本地利用navicate运行SQL文件,出现错误信息: Incorrect table definition;there ...
- mysql运行sql文件出错
从服务器上备份表数据到本地,使用的工具是Navicat,右键表转储sql文件,但是在本地运行sql文件时一直报异常 [Err] 1064 - You have an error in your SQL ...
- 如何在linux中运行sql文件
1.在linux中进入sql命令行 mysql -u root -p 输入密码 2.假设home下面有a.sql文件 先得use databasename,要不会报错 “No Database S ...
- 运行SQL文件报错:Got a packet bigger than 'max_allowed_packet' bytes With statement:
英文意思:需要使用一个和现在相比较大的空间,可能mysql中的默认空间比文件需要的空间要小 解决方法: 1.修改配置文件中mysql的默认空间大小:在MYSQL的配置文件 my.in ...
- PostgreSQL - 用psql 运行SQL文件
对于预先写好的SQL文件,比如/home/user1/updateMyData.sql, 可以有两种方式来运行这个SQL文件. 方式一:连接db后执行SQL文件 首先通过psql连接到对应的db: p ...
- sqlplus运行sql文件
当sql文件的数据比较多的时候,pl/sql运行比较慢,可以通过oracle的sqlplus进行导入: sqlplus user/password@tnsname@sqlfile.sql; 注意如果文 ...
- mysql命令运行sql文件
navicat转储sql,cmd 打开运行 切换到mysql目录下:mysql -uroot -p 回车输入密码 创建数据库语句: CREATE DATABASE `tcc` CHARACTER ...
- MySQL(Navicat)运行.sql文件时报错:[Err] 2006 - MySQL server has gone away 的解决方法
背景: 今天导入一个数据量很大的.sql文件时,报错: 原因: 可能是sql语句过长,超过mysql通信缓存区最大长度. 解决:1. 编辑 MySQL 安装目录下的 my.ini,在最后添加以下内容: ...
- linux中运行.sql文件
1.linux目录结构 2.假设home下面有a.sql文件 先得use databasename,要不会报错 “No Database Selected” 然后source /home/a.sql ...
随机推荐
- DockerPush
1.阿里云镜像发布流程 2.镜像生成 语法:docker commit [OPTIONS] 容器ID [REPOSITORY[:TAG]] [root@pluto data]# docker imag ...
- Docker 初始
1. Docker 是什么? 官网的介绍是"Docker is the world's leading software container platform." 官方给Docke ...
- 深度分析:Java虚拟机类加载机制、过程与类加载器
虚拟机类加载机制是把描述类的数据从 Class 文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被虚拟机直接使用的 Java 类型. 需要注意的是 Java 语言与其他编译时需要进 ...
- 如何在MathType输入手写体a
作为强大的数学公式编辑器,MathType中还能设置各种样式,还支持自定义设置,给大家编辑公式提供了更多的便利.那么有用户问:要如何将输入的字母a变为手写体呢?下面就来一起学习. 输入手写体a的步骤如 ...
- 【GIT】命令笔记
1.将本地代码提交到github等仓库 1.创建仓库省略 2.切换到本地需要上传的地址 :初始化仓库 git init 3.配置git,告诉git你是谁 git config --global use ...
- 【基于PUPPETEER前端自动化框架】【一】TypeScript+Puppeteer+Jest 整合
前提:掌握Jest + Puppeteer 1.Jest环境配置 2.Jest-MATCHERS匹配器 3.Jest-全局变量设置 4.Puppeteer安装 5.Puppeteer元素获取 6.Pu ...
- Jsoup获取网页内容(并且解决中文乱码问题)
1. 根据连接地址获取网页内容,解决中文乱码页面内容,请求失败后尝试3次 private static Document getPageContent(String urlStr) { for (in ...
- 接入twitter第三方登陆接口遇到的一个问题
本地开了 Shadowsocks,然后postman模拟的twitter的接口是请求成功的,然后用php-curl去请求网址,出现以下错误 Failed to connect to api.twitt ...
- selenium+python自动化元素定位
最近学习自动化测试,终于初步学习完成,需要进行博客日志总结,加深巩固自己的知识. 元素的八种定位方式 1.id 以百度为例子 我们在python输入的元素定位语法:bs.find_element_by ...
- mq存储文件
存储文件 启动broker之后我们可以看到下面这些文件 1.config包含了运行期间一些配置信息,主要包括下列信息. consumerFilter.json:主体消息过滤信息 consumerOff ...