2个问题呵:
1 postgesql 远程连接的命令?
在linux下面远程连接服务器端的postgresql,本地已经安装了postgresql;现在假设:
远程的服务器的ip为dstip,端口为dstPort,远程的用户名为user,密码为psd,远程的数据库为mydb
请问该如何写这个命令?另外需要些什么设置?2 用户c语言实现远程连接的代码?
我在postgreSQL的.../src/test/examples里面找到了一个代码,是连接本地的postgreSQL的,但是远程的不知道该怎么连接。
.../src/test/examples/testlibpq3.c
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
const char *paramValues[1];
int paramLengths[1];
int paramFormats[1];
uint32_t binaryIntVal; /*
* If the user supplies a parameter on the command line, use it as the
* conninfo string; otherwise default to setting dbname=postgres and using
* environment variables or defaults for all other connection parameters.
*/
if (argc > 1)
conninfo = argv[1];
else
conninfo = "dbname = postgres";//?????这个参数改如何填写?如果加上远程ip的话?
/* Make a connection to the database */
conn = PQconnectdb(conninfo); /* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
exit_nicely(conn);
}
........
}
1 postgesql 远程连接的命令?
在linux下面远程连接服务器端的postgresql,本地已经安装了postgresql;现在假设:
远程的服务器的ip为dstip,端口为dstPort,远程的用户名为user,密码为psd,远程的数据库为mydb
请问该如何写这个命令?另外需要些什么设置?2 用户c语言实现远程连接的代码?
我在postgreSQL的.../src/test/examples里面找到了一个代码,是连接本地的postgreSQL的,但是远程的不知道该怎么连接。
.../src/test/examples/testlibpq3.c
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
const char *paramValues[1];
int paramLengths[1];
int paramFormats[1];
uint32_t binaryIntVal; /*
* If the user supplies a parameter on the command line, use it as the
* conninfo string; otherwise default to setting dbname=postgres and using
* environment variables or defaults for all other connection parameters.
*/
if (argc > 1)
conninfo = argv[1];
else
conninfo = "dbname = postgres";//?????这个参数改如何填写?如果加上远程ip的话?
/* Make a connection to the database */
conn = PQconnectdb(conninfo); /* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
exit_nicely(conn);
}
........
}
解决方案 »
- mysql-5.0.92.zip 里面找不到setup.exe
- 为什么
- 删除表中记录,为什么提示找不到字段,肯定不是中文字符的问题
- mysql_query函数的问题
- VB + POSTGRESQL。怎样存储图片到数据库中,就像ORACLE的BLOB类型
- 一个关于sql server ce2.0的问题
- 这样的问题怎样解决。
- 关于 mysql 数据库的备份问题
- mysql 和mssql这两个系统的区别
- MySQL5.7 修改 root 用户 host 报错:Operation RENAME USER failed for 'root'@'localhost'
- left join中的问题 拜求!在线等待
- MYSQL复制中的NOW()的问题
pg_hba.conf中:
host all all 127.0.0.1/32 trust
添加:
host <db> 192.168.1.15 255.255.255.0 password连接串:
conninfo = "host=" + _host
+ " port=" + _port
+ " dbname=" + _dbname
+ " user=" + _username
+ " password=" + _password;
mysql -h 192.168.0.1 -u dbuser -p