Freigeben über


MySQL on Nano Server

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

2.      Create a VM in Azure using the Nano Server image in the Azure Gallery. If you don’t have an Azure account, you can get a free 30-day trial.

3.      Download the Technical Preview 5 ISO at the above link and then consult the Nano Server documentation to build a VM.

 

Installing MySQL on Nano Server

Download mysql-5.7.13-winx64.zip to your development machine from https://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:

Enter-PSSession $s  

Now add the MySQL\bin folder to your path environment variable:

$env:path += ";C:\MySQL\bin"

To make this change persist even after your Nano Server machine reboots, enter the following:

setx PATH $env:path /M 

Quick test:

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:\mysql\mysql-init.txt -Encoding Ascii

Pass mysql-init.txt to the MySQL daemon for initialization (notice the double backslashes):

mysqld --init-file=c:\\mysql\\mysql-init.txt --console

Stop the daemon using Ctrl+C and type the following to install the service:

mysqld --install

The service is now installed, but stopped. Go ahead and start it:

Get-Service MySQL

Start-Service MySQL

Get-Service MySQL

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!

Type .\mytest.txt

When you display the content of mytest.txt, you see the system databases.

Congratulations! MySQL is up and running on Nano Server :)

For rich database design experience, I downloaded and installed MySQL Workbench on my development machine and pointed to my Nano Server VM.

 

What’s next?

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.

Happy coding :)

 

ref@

Comments

  • Anonymous
    September 07, 2016
    This MS Post worked Like a Charm :-)http://social.technet.microsoft.com/wiki/contents/articles/34655.nano-server-deploying-mysql-database-server.aspx
  • Anonymous
    November 02, 2016
    Outstanding :-)What about performens on MySQLNano
  • Anonymous
    January 28, 2017
    There is a critical bug with mysql and ssl on nano server, documented here:https://bugs.mysql.com/bug.php?id=84690&thanks=4