How to Create Your Own MySQL Server on Your Own Computer in Windows



MySQL


In this article, we show how to create your own MySQL server on your own computer in windows.

Thus, you run your own server, your own database server.

You can then connect to using localhost and use for projects such as for django or any other internet project.

This can make you cut down on costs.

Though frameworks such as Django come with a database system, MySQLite, that you can use for non-production purposes, some experts recommend that you use the database system that you will use for production from the very beginning of a project. This way, you don't have to worry about any inconsistencies later when you go to production.

In this article, we show how to set up your own MySQL database server on your own computer using your own current IP address for your network.

If you are not interested in remote connection and only want to use the postgresql server on your local machine, then you don't need to worry about IP addresses.

But if you want to run a server that is always up (assuming you keep your system on at home) and one which you and others can connect to from another network, then you tie it to your server.

A local MySQL server needs no internet connection, because you are simply using your own computer (and all the software that's installed on it for the MySQL database server). It's the equivalent to opening up Microsoft Word on your computer, typing in a document, and then saving it to your computer. Of course, for this, no internet connection would be necessary. MySQL or any other database server software functions the same if it were operated locally on a computer. Everything is saved to the computer with no internet connection needed.

Remote connection would require the internet, because it's run from a computer outside that would require the internet in order to be able to save information to a remote computer. It's the equivalent of uploading a video to youtube. For this connection, and other remote connection, you would need internet connection.

So if you are trying to create a database server that allows for remote connection (and not just local operation which means on the computer or laptop you have), then you connect to an IP address.

If the IP address of your network is static (meaning it doesn't change), you can directly use your network's IP address.

If the IP address is dynamic, then more work is required. We must then use a dynamic domain name service. This allows you to use a name instead and then the software tracks changes to the IP addresses and updates it, as it changes.

If you connect to the internet at home through a WIFI system, you can use the IP address of your WIFI system.

If you connect to the internet at home via ethernet, you use the IP address of this ethernet connection.

You can find your computer's IP address in windows, through the command prompt, typing in the following shown below.





When you run this, you can see your computer's IP address.

You can use the IPv4 address of whatever device you are using (whether Wifi or Ethernet if your computer is hardwired to the internet).

Most Wifi systems employ dynamic IP addresses (meaning they change from day to day), so we need to use a dynamic domain name service.

Instead of directly using an IP address for remote connection, what we should do instead is a service that provides dynamic domain name service (DNS). What this means is that instead of using the IP address (which changes), we instead use a hostname (kind of like a domain name for a website) and the service tracks the changes in the IP address of the network. You just have to download

One such website that offers this service is https://www.noip.com/

With this website, you get one hostname for free (as of the time of this writing on 5/28/24).

You tie this hostname to any of the dynamic IP addresses generated by your wifi system. And it tracks changes to the IP address.

So now that you have the IP address (for static addresses) or the hostname (for dynamic addresses), the next thing we need to do is download the MySQL software to our computer.

What we want to download is the MySQL Community Server 8.4.0 LTS.

This can be found at the following link: dev.mysql.com/downloads/mysql/

Click on the MSI installer shown below.


MySQL community server download in windows


During the installation, you will need to specify a password for the root user.

After this has downloaded, you can download MySQL Workbench. This is the GUI that allows you to work with MySQL, similar to pgadmin in PostgreSQL.

Also, after the installation, though, you have the MySQL Command Line Client, it is also nice to be able to carry out MySQL commands through the regular Windows Command Prompt.

For this, you have to make sure that it is in path.

What you need to do is put in the path of the installation of MySQL into the environment variables in Windows.

The path should be, C:\Program Files\MySQL\MySQL Server 8.4\bin

Once this is in the Path variable of Environment variables, then you can use mysql in the Command Prompt.

To log into the root user account, you use the following line specified below.





Then after that, you just type in the password and you have access to MySQL.

One thing we want to do is check to see if our MySQL server is up and running.

To do this in Windows, you go to Services and you go down to the name that you gave for the server.

I gave my MySQL server the name 'MySQLDavidServer'. Thus, this is what I see when I search for it.


How to check if MySQL server is running in windows


We can see that its status is running, so it is fully operational.

One thing we want to do is create a database. Because unlike PostgreSQL, MySQL does not install with a default database. Thus, we have to create one, which is very easy to do.

After you have access to MySQL after logging in with the password, you can specify the following below.





This database should now be created.

You can show this by going back to the MySQL command line client and typing in the line below.





This is shown below.


How to show databases of MySQL server


So you see the database we now created.

Now let's see if this MySQL server works with an actual project.

You can test this out in numerous ways.

One of the ways that you can do this is a script in Python or with a framework such as Django.

Just make sure that if you're using Python or Django that you have the mysqlclient installed. This module allows Python and Django to connect to and communicate with the MySQL server.

Being that I have a django project running on my computer, I have tested out my connection this way.

The code that I used to do this is as shown below.





Once this was done, the connection worked, and we now officially have a MySQL server running on our computer.

One thing worth noting with Django is before I had a PostgreSQL running with Django, where I did all my migrations.

I then connected the MySQL database to this Django project.

And this is what I received when I ran the Django server.


Changing databases in Django


You can see that there are 45 unapplied migrations due to the switch of databases.

This is another evidence that we have completely switched from our original database to another. And now to get all the data to our new database, we have to migrate all the data to this new databases for it to be current to the last one.


Related Resources

How to Connect a PostgreSQL Database in AWS to a Django Project

How to Connect a MariaDB Database in AWS to a Django Project

How to Connect an Oracle Database in AWS to a Django Project



HTML Comment Box is loading comments...