Sql Server For Mac
Here I’ll show you how to install SQL Server on a Mac with VirtualBox running Windows (a free trial edition).
UPDATE (Oct 3, 2017): The content of this article has been revised to reflect changes in the latest General Availability (GA) release of SQL Server for Linux. A new section on restoring from backup.
The result of this is that you’ll have both Windows and SQL Server running on your Mac. And because you’re using VirtualBox, switching between macOS and Windows is as easy as switching between any other application.
Install sql-cli on a Mac. Once you've installed SQL Server on your Mac, you'll probably want to run some queries. Sql-cli is a command line tool that allows you to run SQL queries right from your Mac's Terminal window. SQLPro for MSSQL is the Premier application for editing and viewing SQL Server databases on mac os x. The SQL Server is available for connections once the state is confirmed as running. Connect to SQL Server. Microsoft recently renamed the SQL Operations Studio as Azure Data Studio. Azure Data Studio is available on Windows, Mac, and Linux. If you prefer to create SQL Server 2017 containers, see the SQL Server 2017 version of this article. This image consists of SQL Server running on Linux based on Ubuntu 16.04. It can be used with the Docker Engine 1.8+ on Linux or on Docker for Mac/Windows.
As mentioned, this method involves Windows. If that scares you, then you might be better off installing SQL Server on your Mac via a Docker container. That method doesn’t involve Windows in any shape or form.
But if you don’t mind using Windows (or if you need to), here are the main steps for installing SQL Server for Windows on your Mac using VirtualBox:
- Download and Install VirtualBox
- Create a New Virtual Machine (VM)
- Download the Windows ISO image
- Install Windows
- Download and Install SQL Server
Below are more detailed instructions for each of these steps.
Download and Install VirtualBox
- The first step is to download VirtualBox from the VirtualBox download page.
- Install VirtualBox just as you’d install any other software. Once the .dmg file has downloaded, open it up and double click on the VirtualBox.pkg icon. This opens the installer. Follow the prompts and close the installer once it’s installed.
VirtualBox is virtualization software by Oracle. It allows you to create virtual machines on your computer. This allows you to install other operating systems onto your Mac (or other computer). The benefit of this is that, once you’ve installed another operating system on your Mac, you can run any software that runs on that operating system.
Create a New Virtual Machine (VM)
This is where you create a new virtual machine that you will install Windows on.
- Open VirtualBox (via the Applications folder)
- Click New
- Follow the prompts to the end. Call the virtual machine Windows or Windows 10 or something descriptive. The default settings on each screen should be fine, although it might pay to bump up the memory to around 4GB (or more if you can afford it) when you get to the Memory Size screen. Just be sure to leave enough memory for your host machine.
Once you’ve finished, your new virtual machine will appear in the VirtualBox side panel.
Download the Windows ISO image
Now that we’ve created a virtual machine, we can go ahead and install Windows on that. But first we need to download it.
If you already have access to a fully licensed edition of Windows by all means use that.
If you intend to keep using Windows (i.e. pay for it), download an ISO file from the Microsoft download page.
Otherwise, you can install a free Windows evaluation trial from the Microsoft Evaluation Center. This allows you to install Windows for free, and trial it for 90 days. If you prefer this option, go to the Evaluation Center and select an edition of Windows to download. Note that the Evaluation Center usually only has the Enterprise Edition and Windows Server.
Once downloaded, move the file to the VirtualBox VMs folder. For example /Users/Bob/VirtualBox VMs/. Or even better, just download the file directly to that folder). This isn’t essential though – if you have another place for the file, go ahead and use that instead.
Install Windows
- Double click on your virtual machine in the VirtualBox side panel (like the one with the arrow pointing to it in the above screenshot).
- Use the interface to browse to the Windows ISO file that you downloaded, and click Start.
- Follow the prompts to install Windows.
Once Windows is installed, the Windows desktop will be displayed.
Download and Install SQL Server
These steps are done using Windows inside the virtual machine you just created (not with your macOS).
- Using the Windows VM that you just installed, open up Edge (Microsoft’s web browser) and download the SQL Server installation file from Microsoft’s SQL Server download page (seeing as you’ll be doing this from within the VM, it’s probably easiest to do a web search for “download sql server” or similar, and choosing the official Microsoft website from the results). The Developer edition is fine, but use whichever edition suits you best.
- Run the installer file and follow the prompts. This downloads and installs SQL Server.
Once SQL Server has been installed, a screen will appear with Installation has completed successfully! Keep this screen open for now – this screen has a button to install SQL Server Management Studio (SSMS). See below for how to install SSMS.
Download and Install SQL Server Management Studio (SSMS)
SQL Server Management Studio is a GUI tool from Microsoft that helps you manage SQL Server. SSMS is one of many tools that you can use with SQL Server, so this step is optional. However, if you’re learning how to use SQL Server, you should definitely learn how to use SSMS.
- While still on the previous screen (i.e. the one that reads Installation has completed successfully!), click Install SSMS to download SQL Server Management Studio. This opens the SSMS download page in a web browser. Find the download link (it will read Download SQL Server Management Studio 17.6 or similar, depending on the version at the time of download) and click it to download SSMS.
- Once downloaded, run the installation file and follow the prompts.
Once SSMS has been installed, you can open it via the Windows Start menu.
When you open SQL Server Management Studio, a connection will need to be established to SQL Server. A connection box will pop up, allowing you to enter your details or confirm the ones that have been pre-populated. Go ahead and click Connect to start using SQL Server.
Optional Extra: Install the VirtualBox Guest Additions
Guest Additions is a free optional extra that can make your life easier when working with your virtual machine. Guest Additions provides closer integration between the virtual machine and the host machine. Guest Additions provides features such as shared folders, time synchronization, mouse pointer integration, and more.
The VirtualBox Guest Additions are installed inside the virtual machine after you’ve installed Windows (or other operating system).
For more information about the Guest Additions, as well as installation instructions, see this Guest Additions help article on the VirtualBox website.
(Be sure to checkout the FREE SQLpassion Performance Tuning Training Plan - you get a weekly email packed with all the essential knowledge you need to know about performance tuning on SQL Server.)Years ago when I switched from Windows to Mac, people have told me regularily that I’m crazy. How can I be that stupid to work on MacOS when I’m dependent on SQL Server? In my case it wasn’t that terrible, because my main work is about content creation (writing blog postings, articles, presentations, training videos) and very often I was only connecting through a RDP connection to a remote SQL Server. Therefore running natively on MacOS was not a big deal for me, and for the last resort I always have a Windows VM which runs in VMware Fusion on my Mac.
But since the introduction of the Container concept through Docker and the possibility to run SQL Server directly in a Container, my life was changing even better. Because now I can run SQL Server 2017+ directly on my Mac and I even don’t really need a Windows VM anymore. In this blog posting I want to show you how you can do the same and run SQL Server directly on your Mac in a Docker container.
Installing SQL Server in a Docker Container
Before you can install SQL Server in a Docker Container on the Mac, you have to install and configure of course Docker itself. I don’t want to go into the details how to install Docker itself, because the necessary steps are very well documented.
Before you can create a Docker Container for SQL Server, you have to pull the correct Docker Image from the Docker Registry. In my case I have decided to try out the latest CTP version of SQL Server 2019:
docker pull mcr.microsoft.com/mssql/server:2019-CTP2.1-ubuntu
When you have pulled the image, you can see it with the docker images command in your Terminal:
You can think about a Docker Image like an ISO file: it’s just an image, and you can’t run it directly, because you have to install it. Therefore we also have to “install” the pulled Docker Image. In Docker you can “install” an image by running it. And that creates the actual Docker Container, which is finally the exectuable that you are executing. Let’s run our Docker Image with the docker run command:
docker run -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=passw0rd1!’ -p 1433:1433 –name sql2019_ctp2 -d mcr.microsoft.com/mssql/server:vNext-CTP2.0-ubuntu
As you can see from the command line, you have to pass in a lot of different parameters. Let’s have a more detailed look on them:
- -e ‘ACCEPT_EULA=Y’
- With the -e option you set an environment variable, on which SQL Server is dependent on. In our case we have to accept the EULA to be able to use SQL Server.
- -e ‘SA_PASSWORD=passw0rd1!‘
- With the SA_PASSWORD environment variable we set the password for the SA login.
- -p 1433:1433
- With the -p option we bind a port on our host machine (in my case on the Mac) to a port in the Container. The port on the left side of the colon is the port on the host machine, and the port on the right side of the colon is the port in the Container. In my case I bind the default SQL Server port of 1433 within the Container to the port 1433 on my Mac.
- Therefore I can directly access the exposed SQL Server Container through the IP address of my Mac on the network. If you have multiple SQL Server Containers, you can also bind them to different ports on your host machine to access them independently from each other.
- –name
- With the –name option we assign a custom name to our Docker Container.
- -d
- And with the -d option we specify the Docker Image that we have pulled previously, and that you want to run the Docker Container detached from the Terminal. This just means that you can close your Terminal, and your Docker Container is still running in the background.
After you have executed that Docker command, your Docker Container is up and running.
Accessing SQL Server on a Mac
We have now 2019 up and running in a Docker Container. But how do we access SQL Server? Of course, I can start up a Windows VM, and use SQL Server Management Studio to access SQL Server. But then I’m again dependent on a Windows VM, which also needs periodically updates, and it would be also a huge overhead to deploy a whole Windows VM just for SQL Server Management Studio…
Therefore let’s introduce Azure Data Studio! Azure Data Studio was formerly known as SQL Operations Studio and it is a client application with which you can manage SQL Server – natively on Windows, Linux, and Mac!!!
As you can see from the previous picture, I have connected here directly to localhost, because in the last step we have exposed the port 1433 of the Docker Container to our host machine. Don’t get me wrong: compared to SQL Server Management Studio, Azure Data Studio is “nice” but… 😉
But hey, I can run it directly on my Mac (without the need of a Windows VM), I can run SQL statements, I have access to Estimated and Actual Execution Plans, and very importantly – it’s extensible. What do I need more? For the kind of work that I’m doing, it’s enough.
Restoring your first Database
When you look back to the previous picture, you can see that you got a vanilla installation of SQL Server 2019. There are our system databases, the crazy default settings, and that’s it. There are of course currently no other database. So you have to create your own databases, or you take an existing database (maybe from a Windows-based SQL Server installation) and you restore it in your Docker Container. Let’s do that now.
In my case I want to show you now the necessary steps how to restore AdventureWorks in the Docker Container. First of all you have to copy your backup file into the Docker Container. But you can’t do a regular cp command from the Terminal, because that command has no idea about your Docker Container. Makes somehow sense…
Therefore your Docker installation offers you the command cp with which you can copy a local file into a Docker Container and vice versa. Let’s take now our backup of AdventureWorks and copy it into the folder /var/backups of our Docker Container:
docker cp AdventureWorks2014.bak sql2019_ctp2:/var/backups/AdventureWorks2014.bak
After you have copied the backup file, we can now restore the database. But the destination folders are different as on a Windows-based SQL Server installation, therefore we also have to move our data and log files. Therefore I have executed in the first step the following command to get the logical file names of our database backup.
Youtube Sql Server For Mac Installations
RESTORE FILELISTONLY FROM DISK = ‘/var/backups/AdventureWorks2014.bak’
And based on that information, let’s perform now the restore of our database.
RESTORE DATABASE AdventureWorks2014 FROM DISK = ‘/var/backups/AdventureWorks2014.bak’
WITH
MOVE ‘AdventureWorks2014_Data’ TO ‘/var/opt/mssql/data/Adventureworks2014.mdf’,
MOVE ‘AdventureWorks2014_Log’ TO ‘/var/opt/mssql/data/Adventureworks2014.ldf’
As you can see I’m moving the data and log files into the folder /var/opt/mssql/data. And now we have our AdventureWorks database restored in our Docker Container.
When you are finished with your work in your Docker Container, you can stop the Container with the following command:
docker stop sql2019_ctp2
And with a docker start command, you can restart your Container again:
Access for mac free. docker start sql2019_ctp2
In that case, all the changes that you have done in your Docker Container (like restoring the AdventureWorks database), are persisted across restarts.
Summary
Running SQL Server natively on a Mac or on Linux was always a huge April fool. But with the introduction of Docker, and the SQL Server support for it, it’s now real. You can now run natively SQL Server on the Mac, and with the help of Azure Data Studio you can even access SQL Server with a native MacOS application. We have really exiting times ahead of us!
Microsoft Sql Server For Mac Download
Thanks for your time,
Sql Server For Mac Os X Free Download
-Klaus