Initialize Tinode Server with Custom Data

35 views
Skip to first unread message

Deena Sun

unread,
Jul 25, 2025, 6:44:32 PMJul 25
to Tinode General
Hello! I am trying to set up my own Tinode Server with a MySQL database. I am using the basic docker-compose file for a single instance from the GitHub. I changed just a few things, such as using mysql:8.0. I am able to access Tinode through localhost:6060 on my computer, and I see that I can log in as alice and view some messages. Is there a way I can set up the Tinode server to fill the database with my own custom data and fake users rather than the sandbox users?

Thank you!

Gene

unread,
Jul 26, 2025, 2:17:43 AMJul 26
to Tinode General
Sure, follow instructions here:

Specifically, look at SAMPLE_DATA variable and https://github.com/tinode/chat/blob/master/tinode-db/data.json 

Deena Sun

unread,
Jul 26, 2025, 12:54:43 PMJul 26
to Tinode General
Thanks Gene! I’ll give this a try.

I had a quick follow up question. I'm trying to follow the least access principle model by creating a MySQL database with a dedicated "tinode" user/password. But when I set up my docker configuration file like this:
services:
db:
image: mysql:8.0
container_name: mysql
restart: always
# Use your own volume.
# volumes:
# - <mysql directory in your file system>:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: tinode
MYSQL_USER: tinode
MYSQL_PASSWORD: tinode
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-utinode", "-ptinode"]
timeout: 5s
retries: 10
networks:
- private_net
tinode-server:
image: tinode/tinode-mysql:0.23
platform: linux/amd64
container_name: tinode-server
hostname: tinode-server
depends_on:
- db
restart: always
# You can mount your volumes as necessary:
# volumes:
# # E.g. external config (assuming EXT_CONFIG is set).
# - <path to your tinode.conf>:/etc/tinode/tinode.conf
# # Logs directory.
# - <path to your tinode-0 logs directory>:/var/log
ports:
- "6060:6060"
environment:
MYSQL_DSN: tinode:tinode@tcp(db)/tinode
RESET_DB: true
WAIT_FOR: db:3306
networks:
- private_net
- shared_net

networks:
private_net:
driver: bridge
internal: true
shared_net:

My tinode-server container is unable to start properly because of this error:
```
tinode-server  | 2025/07/26 16:51:56 Database adapter: 'mysql'; version: 113
tinode-server  | 2025/07/26 16:51:56 Database not found. Creating.
tinode-server  | 2025/07/26 16:51:56 Failure: Error 1007 (HY000): Can't create database 'tinode'; database exists
tinode-server  | ./init-db failed. Quitting.
```
I assume this is because in the db service, we already create a database with the name "tinode" via the MYSQL_DATABASE environment variable. But I thought this was necessary to specify so that the MYSQL_USER gets properly created with admin access to the MYSQL_DATABASE.

Is there a way I can set up my docker-compose such that my Tinode server connects via a dedicated user to the MySQL container?

Deena Sun

unread,
Jul 26, 2025, 1:03:54 PMJul 26
to Tinode General
I've tried a few variations with setting "REST_DB" to false in my docker-compose file, which still results in the same error.
environment:
MYSQL_DSN: tinode:tinode@tcp(db)/tinode
RESET_DB: false
WAIT_FOR: db:3306

When I instead try to add NO_DB_INIT, I get an error saying "Database not found."
environment:
MYSQL_DSN: tinode:tinode@tcp(db)/tinode
RESET_DB: true
WAIT_FOR: db:3306
NO_DB_INIT: true
 
As a follow-up, if I add "NO_DB_INIT" does that also prevent me from being able to prepopulate MySQL with the data.json we were talking about earlier? What kind of actions does .init-db handle? (I wasn't able to find the init-db file directly in the Tinode chat GitHub repo)

Gene

unread,
Jul 27, 2025, 11:53:56 AMJul 27
to Tinode General
The user which creates the tinode database (runs init-db) should have permission to create the database.
Then you can run tinode server as a user with just read-write permissions.  

Message has been deleted

Deena Sun

unread,
Jul 27, 2025, 12:01:07 PMJul 27
to Tinode General
If I start the MySQL database and the Tinode server with a docker compose up command, does the Tinode server container try to log in as the "tinode" user (based on ths DSN I've set in my docker-compose file) and create the "tinode" database based on this schema.sql? If I simply try to connect to the MySQL container by using `docker exec -it mysql mysql -u tinode -p` I'm able to log in and perform actions on the "tinode" server.

I found that if I add this command under the db service, the init-db script that the Tinode server container runs seems to work.
db:
image: mysql:8.0
container_name: mysql
restart: always
# Use your own volume.
# volumes:
# - <mysql directory in your file system>:/var/lib/mysql
command: >
bash -c "
docker-entrypoint.sh mysqld &
sleep 5 &&
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e \"DROP DATABASE IF EXISTS ${MYSQL_DATABASE}; GRANT CREATE ON *.* TO '${MYSQL_USER}'@'%'; FLUSH PRIVILEGES;\" &&
wait
"
But for some reason, init-db within the tinode-server container seems to fail with the message that it can't create the database 'tinode' because it already exists if I don't first drop the database via a separate command in the MySQL container.

Gene

unread,
Jul 27, 2025, 12:24:41 PMJul 27
to Tinode General
On Sunday, July 27, 2025 at 7:01:07 PM UTC+3 Deena Sun wrote:
If I start the MySQL database and the Tinode server with a docker compose up command, does the Tinode server container try to log in as the "tinode" user (based on ths DSN I've set in my docker-compose file) and create the "tinode" database based on this schema.sql? If I simply try to connect to the MySQL container by using `docker exec -it mysql mysql -u tinode -p` I'm able to log in and perform actions on the "tinode" server.

I found that if I add this command under the db service, the init-db script that the Tinode server container runs seems to work.
db:
image: mysql:8.0
container_name: mysql
restart: always
# Use your own volume.
# volumes:
# - <mysql directory in your file system>:/var/lib/mysql
command: >
bash -c "
docker-entrypoint.sh mysqld &
sleep 5 &&
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e \"DROP DATABASE IF EXISTS ${MYSQL_DATABASE}; GRANT CREATE ON *.* TO '${MYSQL_USER}'@'%'; FLUSH PRIVILEGES;\" &&
wait
"
But for some reason, init-db within the tinode-server container seems to fail with the message that it can't create the database 'tinode' because it already exists if I don't first drop the database via a separate command in the MySQL container.

If the database already exists and you want to drop and recreate it, then you need to set RESET_DB=true.

Deena Sun

unread,
Jul 27, 2025, 12:31:29 PMJul 27
to Tinode General

I do currently have REST_DB=true in my docker-compose. If I try to compose the db and tinode-server and comment out the command under the "db" service to drop the tinode database, I still receive the following error log:
```
tinode-server  | db (172.20.0.2:3306) open
tinode-server  | 2025/07/27 16:29:11 Database adapter: 'mysql'; version: 113
tinode-server  | 2025/07/27 16:29:11 Database not found. Creating.
tinode-server  | 2025/07/27 16:29:11 Failure: Error 1007 (HY000): Can't create database 'tinode'; database exists
tinode-server  | ./init-db failed. Quitting.
tinode-server exited with code 0
tinode-server  | 2025/07/27 16:29:11 Database adapter: 'mysql'; version: 113
tinode-server  | 2025/07/27 16:29:11 Database not found. Creating.
tinode-server  | 2025/07/27 16:29:11 Failure: Error 1007 (HY000): Can't create database 'tinode'; database exists
tinode-server  | ./init-db failed. Quitting.
tinode-server exited with code 1
```

For reference, here is what my docker-compose file looks like:
services:
db:
image: mysql:8.0
container_name: mysql
restart: always
# command: >
# bash -c "
# docker-entrypoint.sh mysqld &
# sleep 5 &&
# mysql -u root -p${MYSQL_ROOT_PASSWORD} -e \"DROP DATABASE IF EXISTS ${MYSQL_DATABASE}; GRANT CREATE ON *.* TO '${MYSQL_USER}'@'%'; FLUSH PRIVILEGES;\" &&
# wait
# "
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u${MYSQL_USER}", "-p${MYSQL_PASSWORD}"]
timeout: 5s
retries: 10
networks:
- private_net
tinode-server:
image: tinode/tinode-mysql:0.23
platform: linux/amd64
container_name: tinode-server
hostname: tinode-server
depends_on:
db:
condition: service_healthy
restart: always
volumes:
- ./data.json:/opt/tinode/data.json
ports:
- "6060:6060"
environment:
MYSQL_DSN: ${TINODE_MYSQL_DSN}
RESET_DB: true
WAIT_FOR: db:3306
SAMPLE_DATA: "/opt/tinode/data.json"
networks:
- private_net
- shared_net

networks:
private_net:
driver: bridge
internal: true
shared_net:

Gene S

unread,
Jul 27, 2025, 12:57:25 PMJul 27
to tin...@googlegroups.com
On Sun, Jul 27, 2025 at 7:31 PM 'Deena Sun' via Tinode General <tin...@googlegroups.com> wrote:

I do currently have REST_DB=true in my docker-compose. If I try to compose the db and tinode-server and comment out the command under the "db" service to drop the tinode database, I still receive the following error log:
```
tinode-server  | db (172.20.0.2:3306) open
tinode-server  | 2025/07/27 16:29:11 Database adapter: 'mysql'; version: 113
tinode-server  | 2025/07/27 16:29:11 Database not found. Creating.
tinode-server  | 2025/07/27 16:29:11 Failure: Error 1007 (HY000): Can't create database 'tinode'; database exists

You have an empty database named 'tinode', not an existing 'tinode' database. Existence of database is checked by reading from the table kvmeta.

If you want to do something custom, then please read the code.

 
--
You received this message because you are subscribed to the Google Groups "Tinode General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tinode+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/tinode/2b706471-98d3-4daf-83b4-709001d68896n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages