Using sockets for database
Mattermost requires a database back-end. If you plan to run it on the machine, install MySQL or PostgreSQL as the database. In this document let’s understand how you can use sockets for setting up the database.
MySQL
$ mysql -u root -p
CREATE DATABASE mattermostdb;
CREATE USER mmuser IDENTIFIED BY 'mmuser_password';
GRANT ALL ON mattermostdb.* TO mmuser;
PostgreSQL
Install and configure PostgreSQL.
Choose between TCP or UNIX Socket, and jump to the corresponding section.
With TCP socket
Create the new user while connecting to the server as
postgresuser (you will be prompted for a password for the new user):sudo -u postgres createuser -P mmuserCreate the Mattermost database, owned by
mmuseruser:sudo -u postgres createdb -O mmuser mattermostdbIn the connections and authentications section, set the
listen_addresslist line per your needs:/var/lib/postgres/data/postgresql.conf listen_address = 'localhost,my_local_ip_address'
You can use ‘*’ to listen on all available addresses.
Then add a line like the following to the authentication config:
/var/lib/postgres/data/pg_hba.conf # TYPE DATABASE USER ADDRESS METHOD # IPv4 local connections: host all all ip_address/32 md5
Run the setup using:
$ psql --host=ip_address --dbname=mattermostdb --username=mmuser --password
With Unix socket
Create the new user while connecting to the server as
postgresuser:sudo -u postgres createuser mattermost
Create the Mattermost database, owned by
mattermostuser:sudo -u postgres createdb -O mattermost mattermostdb
Setup the Unix socket by adding the following line to
/var/lib/postgres/data/pg_hba.conf:local mattermostdb mattermost peerRestart postgresql.service.
Run the setup using:
sudo -u mattermost psql --dbname=mattermostdb
Configuring Mattermost
Mattermost is configured in
/etc/webapps/mattermost/config.json. Strings need to be quoted.The
DriverNamesetting:mysqlfor MySQL andpostgresfor PostgreSQL.The
DataSource:For MySQL, set it to
mmuser:mmuser_password@unix(/run/mysqld/mysqld.sock)/mattermostdb?charset=utf8mb4,utf8.For PostgreSQL
TCP socket:
postgres://mmuser:mmuser_password@127.0.0.1:5432/mattermostdb?sslmode=disable&connect_timeout=10Unix socket:
postgres:///mattermostdb?host=/run/postgresql, wheremattermostdbis the name of the database and/run/postgresqlis the directory containing the Unix socket.

