Gene <ge...@tinode.co>: Jul 27 08:53AM -0700
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.
On Saturday, July 26, 2025 at 7:54:43 PM UTC+3 Deena Sun wrote:
|
Deena Sun <deen...@berkeley.edu>: Jul 27 09:01AM -0700
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
<https://github.com/tinode/chat/blob/master/server/db/mysql/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.
On Sunday, July 27, 2025 at 8:53:56 AM UTC-7 Gene wrote:
|
Gene <ge...@tinode.co>: Jul 27 09:24AM -0700
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
<https://github.com/tinode/chat/blob/master/server/db/mysql/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.
On Sunday, July 27, 2025 at 8:53:56 AM UTC-7 Gene wrote:
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.
On Saturday, July 26, 2025 at 7:54:43 PM UTC+3 Deena Sun wrote:
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?
On Friday, July 25, 2025 at 11:17:43 PM UTC-7 Gene wrote:
Sure, follow instructions here:
https://github.com/tinode/chat/tree/master/docker
Specifically, look at SAMPLE_DATA variable and
https://github.com/tinode/chat/blob/master/tinode-db/data.json
On Saturday, July 26, 2025 at 1:44:32 AM UTC+3 Deena Sun wrote:
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
<https://github.com/tinode/chat/blob/master/docker/docker-compose/single-instance.yml>.
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!
|
Deena Sun <deen...@berkeley.edu>: Jul 27 09:31AM -0700
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:
On Sunday, July 27, 2025 at 9:24:41 AM UTC-7 Gene wrote:
|
Gene S <or....@gmail.com>: Jul 27 07:57PM +0300
On Sun, Jul 27, 2025 at 7:31 PM 'Deena Sun' via Tinode General <
> 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.
|