Hi, Could you share with me an effective method for initializing the MySQL database from your code?
zerohct opened this issue · 9 comments
Hi, I'm a student, and I'm eager to learn how to create a database directly from your code. My understanding in this area is somewhat limited, so I'm seeking guidance on the process.
As a student, I'm not entirely sure where to start or what tools to use for this task.
Any tips, resources, or examples would be greatly appreciated as I embark on this learning journey.
Thank you in advance for your assistance!
Are there alternative solutions aside from the utilization of Docker?
If I use Docker, is there any change at this position in https://github.com/netless-io/flat-server/blob/main/scripts/prepare-test-env.sh?
Because my knowledge in this area is quite limited, could you please clarify for me?
Sorry for any inconvenience I may have caused and thank you very much for your support.
Is the command to run like this?
wget -O - https://github.com/netless-io/flat-server/raw/main/scripts/prepare-test-env.sh | sh
docker run --name mysql-db -e MYSQL_ROOT_PASSWORD=your_password -d mysql:latest
docker run --name redis-db -d redis:latest
yarn run test:sync:orm
It doesn't need to be docker of course. The code of flat-server has to connect to a mysql service and a redis service. It will read config/development.local.yaml
or config/production.local.yaml
(depending on the env NODE_ENV
) at runtime and connect to these services, see
Lines 7 to 20 in f97c153
So you just have to make sure the services are there, and that's enough. The test:sync:orm
script will create database tables for you.
Once you have prepared the databases, you can start running the server with:
# watch build the server, will generate dist/index.js
$ yarn run start
# start server in another terminal
$ node dist/index.js
Thanks for your support. I will try it.
0.0.0.0
is not a valid address to connect to (ERR_ADDRESS_INVALID). It means that the server listens to all possible addresses that could reach the server. For example localhost
127.0.0.1
192.168.x.y
{your internet ip}
. You can just use 127.0.0.1.