How to Install MySQL Zip File on Windows – A Step by Step Guide

In this tutorial, we’ll discuss how to install MySQL Zip File on Windows (MySQL Portable). Tested on Windows 10, but it should work on other versions of Windows.

Actually, there are a lot of ways we can do to run MySQL without installing it, one way is to use XAMPP Portable, that we have discussed in the previous tutorial: How To Install XAMPP On Windows – A Complete Guide

However, now, XAMPP do not include MySQL anymore (because of Oracle?), it replaced by Maria DB. The last version of MySQL supported by XAMPP was 5.6.

As an alternative, we can use WAMP server or EasyPHP which are still consistent using MySQL, but we still have to install them (lack of portable version).

So, till this date, we can’t install MySQL portable except install MySQL Zip File.

I. Install MySQL Zip File on Windows (MySQL Portable)

In order to be able to install MySQL zip file on Windows, follow these steps:

1 Download and Extract The Zip File

First of all, download the MySQL zipped file by visiting the official download page on http://dev.mysql.com/downloads/mysql/

Download MySQL Zip File From MySQL Webpage

Choose the zip file according to your Windows architecture, 32 bit or 64 bit. In this tutorial, I use the 64-bit version. Then, on the next page, if you don’t want to login/register just click the link No thanks, just start my download

Download MySQL Zip File Without Login

Next, extract the zip file we have downloaded. In this example, I extract it to a directory of E:\mysql-5.7.17 The extracted files look like the following figure:

The Content of MySQL Zip File

2 Add a data Folder and Create a Configuration File


Next, we need to create a folder that will be used for MySQL to place the database files and all correspondent data files such as data tables, stored routines, etc.

On MySQL version 5.6 and earlier, all of the data files are stored by default in a data folder, which is already included in the zip file that we downloaded.

However, starting from MySQL version 5.7, that folder has been removed and now, we are free to choose the name and the location of the folder.

For simplicity, we name the folder data and we place it in the main folder (E:\mysql-5.7.17). In Addition, we also need to create a configuration file named my.ini

The data Folder and The my.ini File

3 Add Some Parameters


Next, we need to add some parameters to the my.ini file. These parameters will be used by MySQL to perform various configuration at runtime.

For simplicity, copy and paste the contents of the my-default.ini file into the my.ini file, then, open that file with notepad (or notepad ++). Next, under [mysqld] section, add the following parameters:

basedir = "/mysql-5.7.17"
datadir = "/mysql-5.7.17/data"
tmpdir = "/mysql-5.7.17/tmp"
port = 3306
server_id = 1
log_error = "mysql_error.log"
pid_file = "mysql.pid"
socket = "/mysql-5.7.17/mysql.sock"

# Optional - Default Configuration
max_allowed_packet = 8M
key_buffer_size=16M

# Where do all the plugins live
plugin_dir = "/mysql-5.7.17/lib/plugin/"
basedir = "/mysql-5.7.17"
datadir = "/mysql-5.7.17/data"
port = 3306
server_id = 1
log_error = "mysql_error.log"
pid_file = "mysql.pid"
socket = "/mysql-5.7.17/mysql.sock"

# Optional - Default Configuration
max_allowed_packet = 8M
key_buffer_size=16M

# Where do all the plugins live
plugin_dir = "/mysql-5.7.17/lib/plugin/"

The content of my my.ini file looks like the following:

MySQL Configuration

The Optional – Default Configuration section is optional, you can remove or change it as needed. Reference to the configurations can be found on the official page: https://dev.mysql.com/doc/refman/5.7/en/server-configuration.html

In addition, we store all MySQL error to mysql_error.log file, otherwise, MySQL will automatically create a file with extension of .err to handle the error message, this also happened to the pid_file and socket configuration file

4 Initialization For The First Time


Furthermore, to be able to run MySQL, first, we need to initialize it. We run this process only once.

This process will create necessary files and databases that used to run MySQL including making a username and optionally a password and set privileges to the user.

There are two statements that we can use to initialize (we must choose one)

mysqld --initialize
or
mysqld --initialize-insecure

The Difference is: mysqld --initialize will create a random password that written to the log file, in this example mysql_log.log file located in the data folder.

While for mysqld --initialize-insecure, there is no password to be set, Nevertheless, we can still create a password later.

By default, the process will create a user to login with root as the username, we can define another username by adding --user option, e.g. mysqld --initialize-insecure --user=agusph

For simplicity, in this example, we will initialize using the default username ( root ) without a password. Open a command prompt and navigate the cursor to the bin folder, then, run the command mysqld --initialize-insecure

How to Install MySQL Zip File on Windows

Wait for a while until the process complete, if successful, the data folder will contain files and folders as shown in the following figure:

The Content of The data Folder After Initialization

5 MySQL is Ready To Use


At this step, MySQL is ready to use. To be able to use MySQL, we need to run the MySQL server. Open a command prompt and type the command mysqld, if successful, the cursor will not return to E:\mysql-7.5.17\bin, as shown below:

Successfully Run MySQL Server

If the cursor back to E:\mysql-5.7.17\bin then some errors has occurred, to solve it, see section II at the bottom of this tutorial.

Now, you can close the command prompt window, although closed, the MySQL server will still running (exists in Windows Task Manager on Processes section).

At this step, we can now use MySQL using root as the username without a password. We can try it using a command prompt or database management application such as phpMyAdmin, HeidiSQL, or Toad for MySQL.

Let’s try with the command prompt. Open a command prompt and then point the cursor to E:\mysql-7.5.17\bin, then type the command mysql -u root

If successful, the pointer will change to mysql> such as the following

Running MySQL Using Command Prompt

6 Shutdown The MySQL Server


Mysql server that has been started, will still live until we turn it off manually or we restart our computer. The MySQL server can be seen in the Windows Task Manager (in Windows 7+ press Ctrl+Shift+Esc)

MySQl Server on Windows Task Manager

To turn it off, we can use the command mysqladmin -u root shutdown as follows:

Shutdown The MySQL Server Using a Command Prompt

If it already turned off, and we run the command, we’ll get an error message like the following:

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (10061)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'

II. Install MySQL Zip File – Handling Error

Sometimes, the installation process did not run in smooth, some error may occur and some of them known when we run the MySQL server using the mysqld command.

As we have discussed previously, if we run mysqld and the cursor back to the bin directory E:\mysql-5.7.17\bin then it signs that some errors have been occurred, for example:

An Error Occured When Running MySQL Server

 

To discover the cause of the error, open the error log file, in this example mysql_error.log file, then find the messages that contains ERROR word, eg:

Handling Error While Installing MySQL Zip File

In the example above,  the error occurs because incorrect type of the command option –initialize-unsecure, while it should be --initialize-insecure (using i, instead of u),

To solve that, we have to run the command again mysqld --initialize-insecure, Note that before executing the command, we have to empty the data folder

Or it could be like this:

MySQL Error: Port 3306 Already Used

means that port of 3306 has been used, there could be another MySQL that run using that port. In the real world, the type of error can be vary, always check the error log file to investigate the error.

In this tutorial, we have discussed how to install MySQL zip file on windows, hope it help.

2 Responses

Leave a comment

Like Us

Social