Deploy And Connect MySQL Server


In this article, I’ll talk about how to deploy MySQL service on a remote Windows server, and then how to connect it locally via Navicat.

Step.1 Download MySQL

You can download MySQL community server installer here. Web installer is not recommended since the remote server has relatively low performance.

https://dev.mysql.com/downloads/installer/

image-20230311132223231

After you downloaded it, just copy it to the remote server.

Step.2 Install MySQL Server

Now, in your Windows server, launch MySQL installer.

Notice that it may take quite a long time due to the low performance of the remote server. So, just be patient.

Below are some important steps during installation.

Choosing a Setup Type
In this step, select custom, since we only need a minimum part of it.

Select Products
The remote server only stores the database, so here we can choose only the MySQL server.

image-20230311133022001

I’ve already installed it, so they turned grey. :P Just select the latest one, and click the right arrow to add it to products to be installed. Then, click next to continue.

Product Configuration

In the Type and Networking panel, you can optionally change the type from Development Computer to Server, since it is really installed on a server computer.

Then, you can just follow the default configuration to the end.

Just make sure you remember the root password!

Step.3 Configure MySQL

First, we need to add it to the system path.

By default, MySQL is installed at C:\Program Files\MySQL\MySQL Server 8.0\bin. Just add this path to the system Path variable.

Then, we need configure MySQL server to make it accessible at out local machine. Open cmd on the server, and execute the following commands.

Reference: https://developer.aliyun.com/article/801237

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
C:\Users\Administrator>mysql -u root -p
Enter password: ********
# Some more output...
mysql> use mysql;
Database changed

mysql> update user set host='%' where user='root';
Query OK, 1 rows affected (0.12 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select User,authentication_string,Host from user;
+-------------+----------------------------------------------------+-----------+
| User | authentication_string | Host |
+-------------+----------------------------------------------------+-----------+
| root | $A$OIJijOuj]5l\%NKRAgdjEedPQZKJ5ZglgTB.OzviB/jR4f4 | % |
+-------------+----------------------------------------------------+-----------+
+ .... | ...... | ...... |
+-------------+----------------------------------------------------+-----------+
4 rows in set (0.01 sec)

You are all done if Host of root is set to %.

Step.4 Update Firewall

Remember to open port 3306 (default port of MySQL) of your remote server.

Step.5 Connect MySQL

In Navicat, create a new MySQL connection. Then, in the configuration panel, enter the host name of your remote server and the root password.

image-20230311135419391

Tada! You successfully connected to your MySQL server! Congratulations!


Troubleshoot

Why MySQL service could not be started?

I don’t know either… MySQL service will automatically start after installation, but if you shut it down, it might not start again properly… :(

So, you can choose to uninstall and then reinstall the server in the MySQL installer. (You can choose not to uninstall the installer.)