PowerShell Basics: How to Install MySQL on a Nano Server
Published Apr 09 2019 01:22 AM 10.1K Views
Microsoft

Some time ago, Pierre and I were delivering a Windows Server session to the Toronto ITPRO Usergroup when the following was asked:

 

“Can you install SQL on a Nano Server?”  

 

SQL requires lots of features to be enabled in the underlying operating system. While it is possible to install SQL on a Server Core offering of Windows Server, albeit painful, SQL cannot be installed on a Nano Server at the time of this post being published. There is a possibility of SQL enablement that could occur with the utilization of containers which we’ll explore in a later post.   With this in mind, it is possible to natively install MySQL on Nano. While it may not be as robust as SQL, for some this may just do the trick. This How-To post will detail the process required to complete this.  

 

Step 1: Setup a Nano Server VM 

  

Step 2: Installing MySQL on Nano Server

  1. Download mysql-8.0.15-winx64.zip and unzip the file to a local folder on your admin machine
  2. Rename the innermost mysql-8.0.15-winx64 folder to MySQL
  3. Run the following PowerShell script from an elevated PowerShell console to copy the binaries to your Nano Server machine:
    $ip = “0.0.0.0” # Nano Server IP address
    $s = New-PSSession -ComputerName $ip -Credential ~\Administrator
    Copy-Item -ToSession $s -Path .\MySQL” -Destination C:\ -Force -Recurse

    

Step 3: Setting up your environment

  1. Remote into your newly created Nano Server machine and enter the following:
    Enter-PSSession $s
  2. Enter the following to add the MySQL\bin folder to your path environment variable:
    $env:path += “;C:\MySQL\bin”
  3. Next you need to enter the following to make this change persist even after the Nano Server reboots:
    setx PATH $env:path /M
  4. Now enter the following to ensure the MySQL instance is present:
    mysql –version   # displays the MySQL version
  5. Enter the following to initialize the MySQL daemon and ignore the warnings for now:
    mysqld –initialize –console
  6. Create mysql-init.txt and replace PASSWORD with your own:
    Set-Content -Value “ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘PASSWORD’;” -Path c:\mysql\mysql-init.txt -Encoding Ascii
  7. Pass mysql-init.txt to the MySQL daemon for initialization:
    mysqld –init-file=c:\\mysql\\mysql-init.txt –console
  8. Stop the daemon using Ctrl+C and type the following to install the service:
    mysqld –install
  9. The service is now installed, and needs to be started with the following:
    Get-Service MySQL
    Start-Service MySQL
    Get-Service MySQL
  10. Display the system databases using the assigned password established when mysql-init.txt was created and yes ignore the warning:
    mysql –user=root –password=myPassword -Bse “SHOW DATABASES;” > mydatabase.txt
      NOTE: The output to a file is being redirected to a text file as interactive sessions are not supported
  11. Enter the following to display the content of the mydatabase.txt
    .\mydatabase.txt

MySQL is now operational on Nano Server.

3 Comments
Brass Contributor

This new post seems to be a rewrite of https://blogs.technet.microsoft.com/canitpro/2016/10/18/step-by-step-installing-mysql-on-nano-server...
However, Nano Server (14393.x), which can be installed on a VM, was end-of-service in October 2018. It seems strange to explain how to install the latest version of MySQL on end-of-service Nano Server.

Microsoft

@かずお 山内 correct.  This post is a rewrite of my original post on CANITPRO.NET.  Our team is updating and transferring posts from the TechNet blog to TechCommunity. Nano server utilization (albeit in a container offering) is still being used today.  Some are even implementing the above offering for IoT deployments. 

Copper Contributor

Hi Anthony Bartolo,

 

Hope you are doing good...!!

 

I'm trying to install the MYSQL5.7 and MYSQL 8.0 on windows 2019 based upon the above steps, but not able to start the service. getting the error like "there is no MYSQL service running".

I 'm following steps from Step 3: Setting up your environment step2(Enter the following to add the MySQL\bin folder to your path environment variable). 

Please suggest.

Version history
Last update:
‎May 21 2019 04:46 AM
Updated by: