Skip to content

Commit 2fabcab

Browse files
committed
Added documentation about the different DATABASE_URL formats for the database types
1 parent 22855b0 commit 2fabcab

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

docs/installation/choosing_database.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,58 @@ want to use it, to be prepared for future use cases.
9999
When you are planning to have a very big database, with a lot of entries and many users which regularly using Part-DB, then you should
100100
use MariaDB or PostgreSQL, as they will perform better in that situation and allow for more advanced features.
101101
If you should use MariaDB or PostgreSQL depends on your personal preference and what you already have installed on your servers and
102-
what you are familiar with.
102+
what you are familiar with.
103+
104+
## Using the different databases
105+
106+
The only difference in using the different databases, is a different value in the `DATABASE_URL` environment variable in the `.env.local` file
107+
or in the `DATABASE_URL` environment variable in your server or container configuration. It has the shape of a URL, where the scheme (the part before `://`)
108+
is the database type, and the rest is connection information.
109+
110+
**The env var format below is for the `env.local` file. It might work differently for other env configuration. E.g. in a docker-compose file you have to remove the quotes!**
111+
112+
### SQLite
113+
114+
```shell
115+
DATABASE_URL="sqlite:///%kernel.project_dir%/var/app.db"
116+
```
117+
118+
Here you just need to configure the path to the SQLite file, which is created by Part-DB when performing the database migrations.
119+
The `%kernel.project_dir%` is a placeholder for the path to the project directory, which is replaced by the actual path by Symfony, so that you do not
120+
need to specify the path manually. In the example the database will be created as `app.db` in the `var` directory of your Part-DB installation folder.
121+
122+
### MySQL/MariaDB
123+
124+
```shell
125+
DATABASE_URL="mysql://user:[email protected]:3306/database?serverVersion=8.0.37"
126+
```
127+
128+
Here you have to replace `user`, `password` and `database` with the credentials of the MySQL/MariaDB user and the database name you want to use.
129+
The host (here 127.0.0.1) and port should also be specified according to your MySQL/MariaDB server configuration.
130+
131+
In the `serverVersion` parameter you can specify the version of the MySQL/MariaDB server you are using, in the way the server returns it
132+
(e.g. `8.0.37` for MySQL and `10.4.14-MariaDB`). If you do not know it, you can leave the default value.
133+
134+
If you want to use a unix socket for the connection instead of a TCP connnection, you can specify the socket path in the `unix_socket` parameter.
135+
```shell
136+
DATABASE_URL="mysql://user:password@localhost/database?serverVersion=8.0.37&unix_socket=/var/run/mysqld/mysqld.sock"
137+
```
138+
139+
### PostgreSQL
140+
141+
```shell
142+
DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=12.19&charset=utf8"
143+
```
144+
145+
Here you have to replace `db_user`, `db_password` and `db_name` with the credentials of the PostgreSQL user and the database name you want to use.
146+
The host (here 127.0.0.1) and port should also be specified according to your PostgreSQL server configuration.
147+
148+
In the `serverVersion` parameter you can specify the version of the PostgreSQL server you are using, in the way the server returns it
149+
(e.g. `12.19 (Debian 12.19-1.pgdg120+1)`). If you do not know it, you can leave the default value.
150+
151+
The `charset` parameter specify the character set of the database. It should be set to `utf8` to ensure that all characters are stored correctly.
152+
153+
If you want to use a unix socket for the connection instead of a TCP connnection, you can specify the socket path in the `unix_socket` parameter.
154+
```shell
155+
DATABASE_URL="postgresql://db_user:db_password@localhost/db_name?serverVersion=12.19&charset=utf8&unix_socket=/var/run/postgresql/.s.PGSQL.5432"
156+
```

0 commit comments

Comments
 (0)