GRASS logo

Note: A new GRASS GIS stable version has been released: GRASS GIS 7. Go directly to the new manual page here

NAME

db.connect - Prints/sets general DB connection for current mapset and exits.

KEYWORDS

database, attribute table, connection settings

SYNOPSIS

db.connect
db.connect help
db.connect [-pc] [driver=name] [database=name] [schema=string] [group=string] [--verbose] [--quiet]

Flags:

-p
Print current connection parameters and exit
-c
Check connection parameters, set if uninitialized, and exit
--verbose
Verbose module output
--quiet
Quiet module output

Parameters:

driver=name
Driver name
Options: dbf,odbc,pg,mysql,sqlite,ogr
Default: dbf
database=name
Database name
Default: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/
schema=string
Database schema
Do not use this option if schemas are not supported by driver/database server
group=string
Default group of database users to which select privilege is granted

DESCRIPTION

db.connect allows the user to set database connection parameters. These parameters are then taken as default values by modules so that the user does not need to enter the parameters each time.

The default database backend in GRASS 6 is DBF.

NOTES

Values are stored in the mapset's VAR file; the connection is not tested for validity.

The -p flag will display the current connection parameters.

The -c flag will silently check if the connection parameters have been set, and if not will set them to use GRASS's default values. (useful in scripts before you attempt to create a new database table)

To connect a vector map to a database table, use v.db.connect or v.db.addtable.

EXAMPLES

DBF

Local storage (the dbf/ subdirectory in the mapset must exist or must be created by the user):
db.connect driver=dbf database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'
db.tables -p

SQLite

Local storage:
db.connect driver=sqlite database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db'
db.connect -p
db.tables -p

The SQLite database file is created automatically when used the first time.

ODBC

Network storage, database tables stored in database "mydb" (may require the use of db.login):
db.connect driver=odbc database=mydb
db.login user=myname [pass=secret]
db.connect -p
db.tables -p

PostgreSQL

Network storage, database tables stored in database "mydb" (may require the use of db.login):
db.connect driver=pg database="host=myserver.itc.it,dbname=mydb"
db.login user=myname [pass=secret]
db.connect -p
db.tables -p

PostgreSQL with different port

Network storage, database tables stored in database "mydb" (may require the use of db.login):
db.connect driver=pg database="host=myserver.itc.it,dbname=mydb,port=6666"
db.login user=myname [pass=secret]
db.connect -p
db.tables -p

MySQL (local)

Local storage (db.login may not be needed):
db.connect driver=mysql database=mydb
db.login user=myname [pass=secret]
db.connect -p
db.tables -p

MySQL (external server)

Network storage, database tables stored in database "mydb" (may require the use of db.login):
db.connect driver=mysql database="host=myserver.itc.it,dbname=mydb"
db.login user=myname [pass=secret]
db.connect -p
db.tables -p

SEE ALSO

db.columns, db.copy, db.drivers, db.login, db.tables, v.db.addtable, v.db.connect

GRASS SQL interface

AUTHOR

Radim Blazek, ITC-Irst, Trento, Italy

Last changed: $Date: 2013-12-14 14:40:25 -0800 (Sat, 14 Dec 2013) $


Main index - database index - Full index

© 2003-2016 GRASS Development Team