Roman Iuvshin
Roman Iuvshin

Reputation: 1912

db2 linux console client

How would I execute a sql script on a remote db2 server?

In MySQL I would have done something like this:

mysql -uroot -proot -h localhost < resources/db_scripts/drop_mysql.sql >> logs/drop_my.log

I would also like to do the same for MSSQL and Sybase.

Upvotes: 2

Views: 937

Answers (2)

AngocA
AngocA

Reputation: 7693

You can do that type of operation in DB2 with the "Data Server client" (it had other names in previous DB2 versions, for example "DB2 Administration client"). This application has a set of tools that permit you to control a local or remote database. The most appropriated tool for your case is called the "Command Window".

In order to start working with remote database via the Command Window, you have to "see" the remote databases, and for this, you catalog a remote machine (catalog admin node), a remote instance (catalog node) and then the database (catalog database). It looks complicated, and to prevent this problem, there is a graphical tool called the DB2 Configure assistant (db2ca) that permits you to configure the DB2 environment.

db2 catalog admin tcpip node NODENAME remote SERVERNAME SYSTEM SERVERNAME
db2 catalog tcpip node INSTNAME remote SERVERNAME server PORTNUM remote_instance INSTANCE system SERVERNAME;
db2 catalog database DBNAME as ALIAS at node INSTNAME

Once you have catalog your remote database, you can do

db2 -tvf resources/db_scripts/drop_mysql.sql -z logs/drop_my.log

As part of your script file, you should have the connection statement (db2 connect to ALIAS user USERNAME using PASSWORD) or you have to establish the connection before call the execution of the script file.

Upvotes: 2

Samet Atdag
Samet Atdag

Reputation: 992

You can use db2 Command line processor as this:

$db2 "select * from table_xyz"

But I think you may need SSH access to remote server.

Upvotes: 0

Related Questions