By default, Ejabberd uses mnesia database and if you are not familiar with this then Ejabberd provides many other database options for you. You can connect with any one of them in which you are comfortable. The advantage of connecting Ejabberd with your familiar database is that you can read data in the database and can create your own web services for reporting and other purposes.
I am going to explain here how can we use Ejabberd with MySQL.
If you are installing Ejabberd from source code then you have to pass MySQL option when you configure Ejabberd. Follow below steps to configure Ejabberd source with MySQL option.
Step 1.
cd ejabberd-source ./configure –enable-mysql
Step 2.
Now you need a MySQL server where you can point your Ejabberd configuration. Ejabberd make use of FULLTEXT indexes with InnoDB. Thus, you need MySQL 5.6 or greater to use with Ejabberd.
Step 3.
You can find the latest schema of the Ejabberd database from here.
https://github.com/processone/ejabberd/blob/master/sql/mysql.sql
Now load this database schema into your database.
Step 4.
Now in Ejabberd configuration file /etc/ejabberd/ejabberd.yml we have to update MySQL configuration.
Change auth method internal to odbc.
auth_method: odbc
And change below configuration as well.
odbc_type: mysql odbc_server: “localhost” odbc_database: “ejabberd” odbc_username: “ejabberd” odbc_password: “password” # If you want to specify the port: odbc_port: 3306
Now you have configured your Ejabberd with MySQL. Now create a new admin user and start using ejabberd.
Change modules to use MySQL instead of Mnesia:
Whatever steps we followed so far only ejabberd authentication is moved from mnesia to MySQL, other modules are still using internal database. To globally move default database to MySQL add below configuration in your ejabberd.yml.
default_db: odbc
In case if you are stuck somewhere feel free to write to me in the comments below.
Leave a Reply