db.connect(1grass)

πŸ’– db.connect β€” the bestie that sets up ur database connection πŸ’–

okay so hi bestie!! welcome to db.connect (that's the manual name, it's from the GRASS User's Manual, cute right) ✨ This one prints and/or sets the general DB connection for the current mapset. That's it. That's the whole gig. But the whole gig is IMPORTANT so pay attention bestie 🌸


✨ KEYWORDS ✨

database, attribute table, connection settings β€” yes those are the group chat tags, thank u for asking πŸ’…


🌈 SYNOPSIS 🌈

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

πŸŽ€ FLAGS πŸŽ€

  • -p β€” print the current connection parameters and then dip. exit. done. πŸ‘‘
  • -g β€” print current connection parameters using shell style and exit. BUT β€” and this is the tea β€” it's [deprecated]. like, it's being retired. use format=shell instead bestie, fr fr. πŸ’€
This flag is deprecated and will be removed in a future release. Use format=shell instead.
  • -c β€” check the connection parameters, set them if they're uninitialized, then exit. quiet little caretaker energy. 🫢
  • -d β€” set from default settings and exit. lowkey a glow-up: it overwrites current settings if they're already initialized, so don't be shocked if ur old setup gets replaced ✨
  • --help β€” print usage summary. the classic. πŸ’–
  • --verbose β€” verbose module output, i.e. she's talking more now πŸ—£οΈ
  • --quiet β€” quiet module output, i.e. absolutely no yapping 🀫
  • --ui β€” force launching the GUI dialog. main character energy, but with buttons. πŸ¦‹

πŸ“ PARAMETERS πŸ“

  • driver=name β€” name of the database driver. Options: dbf, mysql, odbc, ogr, pg, sqlite Default: sqlite
  • database=name β€” name of the database. Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
  • schema=name β€” database schema.
Do not use this option if schemas are not supported by the driver/database server. like seriously, don't. it's giving "unsupported" 😭
  • group=string β€” default group of database users to which select privilege is granted. yes, a whole group. very generous of u. πŸ’œ
  • format=name [required] β€” output format. this one is required bestie, no skipping it. Options: plain, shell, json Default: plain
    • plain: plain text output ✏️
    • shell: shell script style output 🐚
    • json: JSON (JavaScript Object Notation) 🧚

πŸ’… DESCRIPTION πŸ’…

so like, db.connect lets u set the database connection parameters. then those parameters get picked up as the default values by other modules, so u don't have to type them in every single time like some kind of 1800s peasant. periodt.

the default database backend in GRASS? that's SQLite, and it has been since version 7. iconic. no cap. πŸ‘‘


🌸 NOTES 🌸

okay the important stuff, don't scroll past this:

  • Values get stored in the mapset's VAR file. and listen β€” the connection is NOT tested for validity. she writes it and moves on, she does not check ur homework. πŸ™ˆ
  • The -p flag will display the current connection parameters.
  • The -c flag will silently check if the connection parameters have been set, and if they haven't, it'll set them to use GRASS's default values. lowkey a lifesaver in scripts before u attempt to create a new database table. 🫢
  • To connect a vector map to a database table, use v.db.connect or v.db.addtable. different module, different vibe, still ur friend. 🌈

⭐ 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. it just ✨appears✨.

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.

Local storage β€” and heads up, the dbf/ subdirectory in the mapset must exist, or u gotta create it urself:

db.connect driver=dbf database=’$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/’
db.tables -p

See DBF database driver for details.

also it literally says "not recommended" in the heading so…… read the room bestie πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

  • db.columns, db.copy, db.drivers, db.login, db.tables, v.db.addtable, v.db.connect
  • GRASS SQL interface

πŸ‘‘ AUTHORS πŸ‘‘

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

πŸ’œ SOURCE CODE πŸ’œ

Available at: db.connect source code (history)

Latest change: Monday Nov 03 07:16:48 2025 in commit: c96796774942e46bbababcd652d3986d4e295665

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


and that's the whole page bestie!! this was GRASS 8.5.0, Β© 2003-2026 GRASS Development Team, and it's the GRASS 8.5.0 Reference Manual β€” so like, u were reading the very same GRASS 8.5.0 / db.connect(1grass) energy the whole time. go set those connection params, u absolute icon πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from