This template will work immediately on any railway project that has a MySQL database deployed. However, it uses the root
user for access, which is not ideal.
For better security, you should set up a dedicated exporter
user in your MySQL DB. The following are detailed instructions for setting that up and adjusting the Railway environmental variables:
-
log into your MySQL DB locally using Railway's connection procedures. These are listed in your MySQL details page.
-
run the following commands to create a new user named
exporter
. Be sure to replaceXXXXXXXX
with a strong password of your choosing:
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
-
Return to the Railway UI. Navigate to your MySQL Collector service and add one new environmental variable: create a key called
MYSQL_EXPORT_PASSWORD
and set the value to your new password. TheMYSQL_EXPORT_USER
variable is already set toexporter
. -
Update the
Dockerfile
and the.my.cnf
file in your github repo. The appropriate replacement lines are already present, but commented out. Comment-out the old lines and uncomment these new lines. Push your changes. Railway will redeploy the collector with the new settings. Your collector is now using a dedicatedexporter
user instead of theroot
user!