This guide will walk you through the process of setting up a MySQL server using Docker and running a Go application that interacts with it.
First, we need to set up a MySQL server. We will use Docker to run a MySQL server with preloaded employees data (for demo). Run the following command in your terminal:
docker run -d --name mysql-employees \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=college \
genschsa/mysql-employees
NOTE :Make sure to replace college with your desired password.
Set the password in an environment variable for easier configuration:
export DB_PASSWORD=college
-
Define your MySQL database configuration in your Go application.
-
Ensure you have Xray installed and imported in your Go application.
-
Checkout Integration.md for a detailed documentation and main.go for code sample demonstrating how to connect to MySQL using Xray.
-
Once you have the code, run the following commands:
go mod tidy
go run example/mysql/main.go