データベースのURL scheme

データベースのURL scheme

[20] 色々なプログラミング言語ライブラリーなどでは、 接続先のデータベースやオプションを指定するために、 URL が用いられています。

意味

[21] そもそも URL の多くは、何らかの意味のデータベースに接続して情報を得たり、 書き込んだりするものです。例えば https: URLHTTPS プロトコルを介してハイパーテキストデータベースにアクセスすることを表しています。

[22] 本項でいう「データベース」は、それよりも限定されたもので、 プログラムが情報の保持に用いる関係データベースやいわゆる NoSQL データベースなどです。

[5] 本項に該当する URL の多くは、接続先のデータベースを表しています。 すなわち、データベースへ接続するために必要なプロトコルホストデータベース名、接続オプションなどを URL に含めています。

[7] データベース内のデータにまでアドレス付けしている URL scheme は今のところなさそうです。

URL scheme

[4] データベースの種類 (接続プロトコルの種類) ごとに、 色々な URL scheme が使われています。

[2] データベースを表す URL scheme

標準化

[6] あらゆる点でほとんど実装依存であり、標準化の動きもありません。 みな似たような構文と意味に収まっていますが、細かい点に色々と違いがありそうです。

環境変数 DATABASE_URL

[14] Ruby on Rails設定ファイル内で接続先のデータベースURL で指定できるとしています。加えて、環境変数 DATABASE_URL によって指定する方法も提供しています。

歴史

[8] ODBCPerlモジュールDBI は、接続先のデータベースの種類 (プロトコル) によらず (ほぼ) 共通化された構文の接続文字列DSN を採用していました。 これが単一の文字列によって接続先データベースの記述を統合的に扱おうとした事例のはしりなのでしょうが、 接続文字列は構文的に URL とまったく異なっていましたし、 DSNURL とは見なされていませんでした。

メモ

[9] データベースへ接続するためにはホストプロトコルデータベース名など色々なオプションを指定しなければなりません。 データベースを扱うアプリケーションの起動時や設定ファイルでこれを一々指定するのも中々大変ですし、 複数のデータベースに接続する巨大なアプリケーションではデータベース管理だけで一苦労です。 その点、 URL のようにこうした指定を1つの文字列にまとめられると、 データベースごとに1文字列を指定できるようにすれば良いだけなので、 開発者運用担当者も楽になります。

[1] Engine Configuration — SQLAlchemy 0.9 Documentation ( 版) <http://docs.sqlalchemy.org/en/rel_0_9/core/engines.html#database-urls>

[3] Data Services — Stackato 3.0.1 documentation ( 版) <http://docs.stackato.com/3.0/user/services/data-services.html#database-url>

It contains the connection string for the bound database in the following format:

protocol://username:password@host:port/database_name

[10] Welcome to Django-environ’s documentation! — Django-environ 0.4.0 documentation () <https://django-environ.readthedocs.io/en/latest/>

db_url

PostgreSQL: postgres://, pgsql://, psql:// or postgresql://

PostGIS: postgis://

MySQL: mysql:// or mysql2://

MySQL for GeoDjango: mysqlgis://

SQLITE: sqlite://

SQLITE with SPATIALITE for GeoDjango: spatialite://

LDAP: ldap://

cache_url

Database: dbcache://

Dummy: dummycache://

File: filecache://

Memory: locmemcache://

Memcached: memcache://

Python memory: pymemcache://

Redis: rediscache://

search_url

ElasticSearch: elasticsearch://

Solr: solr://

Whoosh: whoosh://

Xapian: xapian://

Simple cache: simple://

email_url

SMTP: smtp://

SMTP+SSL: smtp+ssl://

SMTP+TLS: smtp+tls://

Console mail: consolemail://

File mail: filemail://

LocMem mail: memorymail://

Dummy mail: dummymail://

[11] seamusabshere/database_url: Convert back and forth between Heroku-style ENV['DATABASE_URL'] and Rails/ActiveRecord-style config/database.yml hashes. () <https://github.com/seamusabshere/database_url>

[12] Riding Rails: Rails 4.1.0: Spring, Variants, Enums, Mailer previews, secrets.yml () <http://weblog.rubyonrails.org/2014/4/8/Rails-4-1/>

Second is that we’ve added support for database URLs in database.yml, and that we by default will be referring to ENV-backed URLs in the generated files.

[13] John Griffin: Rails 4.1: Database URLs (John Griffin著, ) <http://www.johng.co.uk/2014/04/29/rails-41-database-urls/>

[15] Environment Variables - GitLab Documentation () <https://docs.gitlab.com/ce/administration/environment_variables.html>

DATABASE_URL string The database URL; is of the form: postgresql://localhost/blog_development

[16] Environment Variables - GitLab Documentation () <https://docs.gitlab.com/ce/administration/environment_variables.html>

The recommended way of specifying your database connection information is to set the DATABASE_URL environment variable. This variable only holds connection information (adapter, database, username, password, host and port), but not behavior information (encoding, pool). If you don't want to use DATABASE_URL and/or want to set database behavior information, you will have to either:

copy our template file: cp config/database.yml.env config/database.yml, or

set a value for some GITLAB_DATABASE_XXX variables

[17] Manual :: The Data Source Name () <http://pear.php.net/manual/en/package.database.db.intro-dsn.php>

To connect to a database through PEAR::DB, you have to create a valid DSN - data source name. This DSN consists in the following parts:

phptype: Database backend used in PHP (i.e. mysql , odbc etc.)

dbsyntax: Database used with regards to SQL syntax etc. When using ODBC as the phptype, set this to the DBMS type the ODBC driver is connecting to. Examples: access, db2, mssql, navision, solid, etc.

protocol: Communication protocol to use ( i.e. tcp, unix etc.)

hostspec: Host specification (hostname[:port])

database: Database to use on the DBMS server

username: User name for login

password: Password for login

proto_opts: Maybe used with protocol

option: Additional connection options in URI query string format. options get separated by &

The format of the supplied DSN is in its fullest form:

phptype(dbsyntax)://username:password@protocol+hostspec/database?option=value

Most variations are allowed:

phptype://username:password@protocol+hostspec:110//usr/db_file.db

phptype://username:password@hostspec/database

phptype://username:password@hostspec

phptype://username@hostspec

phptype://hostspec/database

phptype://hostspec

phptype:///database

phptype:///database?option=value&anotheroption=anothervalue

phptype(dbsyntax)

phptype

The currently supported database backends are:

dbase -> dBase

fbsql -> FrontBase (functional since DB 1.7.0)

ibase -> InterBase (functional since DB 1.7.0)

ifx -> Informix

msql -> Mini SQL (functional since DB 1.7.0)

mssql -> Microsoft SQL Server (NOT for Sybase. Compile PHP --with-mssql)

mysql -> MySQL (for MySQL <= 4.0)

mysqli -> MySQL (for MySQL >= 4.1) (requires PHP 5) (since DB 1.6.3)

oci8 -> Oracle 7/8/9

odbc -> ODBC (Open Database Connectivity)

pgsql -> PostgreSQL

sqlite -> SQLite

sybase -> Sybase

With an up-to-date version of DB, you can use a second DSN format

phptype(syntax)://user:pass@protocol(proto_opts)/database

[18] go-sql-driver/mysql: Go MySQL Driver is a lightweight and fast MySQL driver for Go's (golang) database/sql package () <https://github.com/go-sql-driver/mysql>

The Data Source Name has a common format, like e.g. PEAR DB uses it, but without type-prefix (optional parts marked by squared brackets):

[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

A DSN in its fullest form:

username:password@protocol(address)/dbname?param=value

[19] The DB-URI — TurboGears 1.0 documentation () <http://turbogears.org/1.0/docs/DbUri.html>

postgres://username@hostname/databasename

mysql://username:password@hostname:port/databasename

sqlite://path/to/file

postgres:///var/run/postgresql/test?debug=1

mysql://localhost/database?unix_socket=/var/lib/mysql/socket