One of Nano Server’s core scenarios is to serve as a lightweight OS for born-in-the-cloud applications running in a VM or a container. Nano Server already supports ASP.NET Core (aka ASP.NET 5) with IIS, Node.js, Python & Django, and now, we’re happy to announce support for MySQL.
The instructions in this blog explain how to get MySQL running on Nano Server. If you want to try this on a Nano Server VM, with Windows Server 2016 Technical Preview 5 there are three ways you can quickly get a VM:
1. Download the developer VHD at the above Technical Preview 5 link
Installing MySQL on Nano Server
Download mysql-5.7.13-winx64.zip to your development machine from http://dev.mysql.com/downloads/mysql/, unzip the file to a local folder, and rename the innermost mysql-5.7.13-winx64 folder to “MySQL” for simplicity.
Use the following PowerShell script from an elevated PowerShell console, classic or ISE, to copy the binaries to your Nano Server machine:
$ip = “0.0.0.0” # the IP address of your Nano Server machine
$s = New-PSSession -ComputerName $ip -Credential ~Administrator
Copy-Item -ToSession $s -Path .MySQL” -Destination C: -Force -Recurse
Setting up your environment
Remote into your Nano Server machine:
Now add the MySQLbin folder to your path environment variable:
$env:path += “;C:MySQLbin”
To make this change persist even after your Nano Server machine reboots, enter the following:
setx PATH $env:path /M
mysql –version # displays the MySQL version
Now let’s initialize the MySQL daemon (ignore the warnings):
mysqld –initialize –console
Create mysql-init.txt (replace ‘myPassword’ with your own password):
Set-Content -Value “ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘myPassword’;” -Path c:mysqlmysql-init.txt -Encoding Ascii
Pass mysql-init.txt to the MySQL daemon for initialization (notice the double backslashes):
mysqld –init-file=c:mysqlmysql-init.txt –console
Stop the daemon using Ctrl+C and type the following to install the service:
The service is now installed, but stopped. Go ahead and start it:
Let’s display the system databases. Remember to replace myPassword with the same password you used when you created mysql-init.txt (ignore the warning):
mysql –user=root –password=myPassword -Bse “SHOW DATABASES;” > mytest.txt
We are redirecting the output to a file because interactive sessions are not supported!
When you display the content of mytest.txt, you see the system databases.
Congratulations! MySQL is up and running on Nano Server
MySQL is the latest addition to a series of app frameworks we are documenting how to get running on Nano Server. Let us know what your favorite app framework is, and be generous with your feedback on your Nano Server developer experience.