Dela via


Step-By-Step: Installing MySQL on Nano Server via PowerShell

Recently, Pierre Roman was in town presenting 10 Things I like About Windows Server 2016 to the Toronto ITPRO Usergroup. While presenting, he white-boarded a couple of questions for Pierre and I to address on CANITPRO.NET later via a blog post.

MySQL Nano

One such question was as follows:

“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 Step-By-Step post will detail the process required to complete this.

 

Step 1: Setup a Nano Server VM

MVP Sean Kearney does an excellent job of detailing the setup in his post: Step-By-Step: Deploying Nano Server Found in Windows Server 2016 TP5

 

Step 2: Installing MySQL on Nano Server

  1. Download mysql-5.7.13-winx64.zip and unzip the file to a local folder on your admin machine

  2. Rename the innermost mysql-5.7.13-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.