db.connect(1grass)

db.connect1grass

Prints/sets general db connection for current mapset.

Usage

db.connect

db.connect --help

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

Keywords

database, attribute table, connection settings

Overview

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 GIS is SQLite (since version 7).

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

SQLite (default backend)

Local storage:

db.connect -d
db.connect -p
db.tables -p

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

See SQLite database driver for details.

PostgreSQL (local connection)

Local storage, database tables stored in database "mydb" (may require the use of db.login):

db.connect driver=pg database=mydb
db.login user=myname pass=secret
db.connect -p
db.tables -p

See PostgreSQL database driver for details.

PostgreSQL (network connection)

Network storage, database tables stored in database "mydb" (may require the use of db.login):

db.connect driver=pg database=mydb
db.login user=myname pass=secret host=myserver.com port=6666
db.connect -p
db.tables -p

See PostgreSQL database driver for details.

MySQL (local connection)

Local storage, database tables stored in database "mydb" (may require the use of db.login):

db.connect driver=mysql database=mydb
db.login user=myname pass=secret
db.connect -p
db.tables -p

See MySQL database driver for details.

MySQL (network connection)

Network storage, database tables stored in database "mydb" (may require the use of db.login):

db.connect driver=mysql database=mydb
db.login user=myname pass=secret host=myserver.com
db.connect -p
db.tables -p

See MySQL database driver for details.

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

See ODBC database driver for details.

DBF (local, not recommended)

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

See DBF database driver for details.

Source code

Available at: db.connect source code (history)

Accessed: Monday Feb 24 17:50:22 2025

Main index | Database index | Topics index | Keywords index | Graphical index | Full index

© 2003-2025 GRASS Development Team, GRASS GIS 8.4.1 Reference Manual

Releases

10 releases since Debian 4.0 (Etch); the text changed 9 times.

  1. 4.0
  2. 5.0
  3. 6.0
  4. 7
  5. 8
  6. 9
  7. 10
  8. 11
  9. 12
  10. 13

Authors

Main author: Radim Blazek, ITC-Irst, Trento, Italy
GRASS 7 improvements: Martin Landa, Markus Metz

From grass-doc 8.4.1-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.