Steps to set-up a new project on the local machine using mysql and redis

Cecilia Orji
5 min readApr 25, 2023

--

new project

Table of contents

- Introduction

- Setting up the IDE

- Setting up the Database

- Setting up the environment variables

- Creating a redis cluster

- Creating a redis instance using docker

Introduction

This documentation details how to set up a new project on your local machine and the changes required to implement the service or app.

Setting up the IDE

Assuming this is a Golang project, you will need to have an IDE installed on your machine, such as Goland by Jetbrains or Visual Studio Code. If using Visual Studio Code, make sure to install the Go extension as well.

Before getting started, ensure that Golang is installed on your machine. If not, you can download the latest version from the official website at https://golang.org/dl/.

Next, install Git on your machine, as it will be required to clone the repository. You can download the official installer for your operating system from the Git website.

Once Git is installed, clone the repository using either ssh or https. Using ssh is preferable if possible.

git clone [repository URL]

. Install the necessary dependencies in the go mod file using go get.

go get [dependency name]

The next thing is to set-up the database and for this we will be looking at mysql.

Setting up the Database

The database is mysql which is a RDBS. Below is a process to have it set up;

. Install MySQL server on your local machine. You can download the installer from the official MySQL website: https://dev.mysql.com/downloads/ If you have brew installed on your machine, you can install using the command below.

brew install mysql

. Once the installation is complete, start the MySQL server.

brew services start mysql

. Create a new database and user account for your project. You can use the MySQL command-line client or a graphical client like MySQL Workbench: https://dev.mysql.com/downloads/workbench/ to do this.

. Grant the user account the necessary permissions to access the database.

To create a database using the CLI, you do the following;

a. Open the terminal and login to the MySQL server as the root user by running the following command:

mysql -u root -p

when prompted, enter the root user password and if none just click on enter.

b. Create a new database by running the following command:

CREATE DATABASE mydatabase;

Replace ‘mydatabase’ with the name you want to give to your new database.

c. Create a new table by running the following command:

CREATE TABLE orders (
id INT PRIMARY KEY,
customer_id INT,
order_date DATETIME,
total_price DECIMAL(10, 2),
FOREIGN KEY (CustomerID) REFERENCES Users(ID)
);

Replace ‘orders’ with the name you want to give to your new table. This example creates a table with 4 columns, “id”, “customer_id”, “order_date” and “total_price”.

d. You can insert, query or perform any other operations on the db.

To create a database using the GUI mysql workbench, you do the following;

e. Open the installed MySQL Workbench on your machine.

this is how it looks

f. Click on the “Create a new schema in the connected server” button in the home screen. Enter the name for the new schema and click on apply.

another way to create a new schema

g. There are different ways of creating tables on the workbench as well. Select the schema, go to tables, right click and select create table. give the table name.

h. Enter a name for the columns, select the data type, and set any additional properties as needed.

i. Click on the “Apply” button to save the changes.

j. You can also create your schema and tables using the icons shown below

creating table from the schema

k. Another method is to import the db.sql file or .sql for the project to the workbench.

l. Click on server at the top of the worbench, select data import

importing table into mysql workbench

m. Select import from self contained file, click on the dot to search for the file you want to import from your system, click on open

another method to import tables

n. Select the default target schema i.e the schema you want the sql file to be imported into

how to select the schema you want the data/table to be imported to

o. Click on start import at the bottom and this will automatically import your schema tables and columns.

Setting up the environment variables

After setting up the database, you need to set up your environmental variables in a file called .env which is created at the root. Environmental variables are values or settings that can affect the behaviour of a computer program or operating system.

These includes the port, db_user, db_password, db_name, jwt_secret, redis_password and so on.

We will continue with the rest topics in the next post. Let me know what you think in the comment section.

Creating a redis cluster

Creating a redis instance using docker

--

--

Cecilia Orji
Cecilia Orji

Written by Cecilia Orji

A Golang developer | love programming as it helps to solve problems | hobbies : listening to radio, reading and a good Kdrama

No responses yet