如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

时间:2022-11-29 23:40:16

I want to run SQLServer on my Mac but I can't do it natively. How can I host a SQLServer with VirtualBox and connect to it from my MacBook for local development?

我想在我的Mac上运行SQLServer,但我不能在本机上运行它。如何使用VirtualBox托管SQLServer并从我的MacBook连接到本地开发?

1 个解决方案

#1


84  

  1. Download VirtualBox
  2. 下载VirtualBox
  3. Download a Windows 10 ISO from here
  4. 从这里下载Windows 10 ISO
  5. Create a new Windows 10 VM with VirtualBox. When it asks for the "Virtual Optical Disk File", point it to the ISO download from Step 2:
  6. 使用VirtualBox创建新的Windows 10 VM。当它要求“虚拟光盘文件”时,将其指向步骤2中的ISO下载:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Continue with the Windows 10 setup
  2. 继续Windows 10安装程序
  3. In the Windows VM, download and install SQL Server (I used Express)
  4. 在Windows VM中,下载并安装SQL Server(我用的是Express)
  5. When the SQL Server installation finishes, install the tool (SSMS) which we will need later
  6. SQL Server安装完成后,安装我们稍后需要的工具(SSMS)

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. With SSMS, create a new database (I called mine testdatabase)
  2. 使用SSMS,创建一个新数据库(我称为我的testdatabase)

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

8.1. Create a new Login: right click on Security > New > Login... Be sure to select the SQL Server authentication option.

8.1。创建一个新的登录:右键单击安全性>新建>登录...确保选择SQL Server身份验证选项。

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

8.2. In the Server Roles tab, select the sysadmin option: 如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

8.2。在“服务器角色”选项卡中,选择sysadmin选项:

8.3. In the User Mapping tab, map the login to the database, and check all assign the role memberships:

8.3。在“用户映射”选项卡中,将登录映射到数据库,并选中所有分配角色成员身份:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Open the server properties (right click the root level object). Go to the Security tab, and switch the Server Authentication mode to SQL Server and Windows Authentication mode:
  2. 打开服务器属性(右键单击根级别对象)。转到“安全”选项卡,然后将“服务器身份验证”模式切换到SQL Server和Windows身份验证模式:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Open the Windows Services program, and find the SQL Server Browser. Open its properties and change the Startup type to automatic:
  2. 打开Windows服务程序,找到SQL Server Browser。打开其属性并将“启动”类型更改为“自动”:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

11.1. Open the Sql Server Configuration Manager program. Navigate to the Protocols under the SQL Server Network Configuration and Enable the TCP/IP option:

11.1。打开Sql Server配置管理器程序。导航到SQL Server网络配置下的协议并启用TCP / IP选项:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

11.2. Open the TCP/IP properties switch to the IP Addresses tab. Make a note of the IP Address field under IP2 (you will need this later):

11.2。打开TCP / IP属性切换到IP地址选项卡。记下IP2下的IP地址字段(稍后需要):

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

11.3. Set the TCP Port under IPALL to 1433:

11.3。将IPALL下的TCP端口设置为1433:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Configure the Firewall on the Windows VirtualBox to allow 1433 to be unblocked (I just disabled the whole firewall, probably not the best option):

    在Windows VirtualBox上配置防火墙以允许1433被解除阻塞(我只是禁用了整个防火墙,可能不是最佳选择):

  2. In your Macbook's VirtualBox app, open the settings for the Windows VM and go to the Network tab. Set the Attached to dropdown to NAT, then click Port Forwarding. Add a rule to forward the VM's 1433 port to your localhost's 1433 port. The Guest IP will be the IP from Step 11.2:

    在Macbook的VirtualBox应用程序中,打开Windows VM的设置并转到“网络”选项卡。将Attached to下拉列表设置为NAT,然后单击Port Forwarding。添加规则以将VM的1433端口转发到localhost的1433端口。来宾IP将是步骤11.2中的IP:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer


You should now be able to connect to your SQLServer from your macbook with a connection string something like this:

您现在应该可以使用以下连接字符串从macbook连接到SQLServer:

jdbc:sqlserver://127.0.0.1;databaseName=testdatabase

JDBC:SQLSERVER://127.0.0.1;的databaseName = testdatabase

#1


84  

  1. Download VirtualBox
  2. 下载VirtualBox
  3. Download a Windows 10 ISO from here
  4. 从这里下载Windows 10 ISO
  5. Create a new Windows 10 VM with VirtualBox. When it asks for the "Virtual Optical Disk File", point it to the ISO download from Step 2:
  6. 使用VirtualBox创建新的Windows 10 VM。当它要求“虚拟光盘文件”时,将其指向步骤2中的ISO下载:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Continue with the Windows 10 setup
  2. 继续Windows 10安装程序
  3. In the Windows VM, download and install SQL Server (I used Express)
  4. 在Windows VM中,下载并安装SQL Server(我用的是Express)
  5. When the SQL Server installation finishes, install the tool (SSMS) which we will need later
  6. SQL Server安装完成后,安装我们稍后需要的工具(SSMS)

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. With SSMS, create a new database (I called mine testdatabase)
  2. 使用SSMS,创建一个新数据库(我称为我的testdatabase)

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

8.1. Create a new Login: right click on Security > New > Login... Be sure to select the SQL Server authentication option.

8.1。创建一个新的登录:右键单击安全性>新建>登录...确保选择SQL Server身份验证选项。

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

8.2. In the Server Roles tab, select the sysadmin option: 如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

8.2。在“服务器角色”选项卡中,选择sysadmin选项:

8.3. In the User Mapping tab, map the login to the database, and check all assign the role memberships:

8.3。在“用户映射”选项卡中,将登录映射到数据库,并选中所有分配角色成员身份:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Open the server properties (right click the root level object). Go to the Security tab, and switch the Server Authentication mode to SQL Server and Windows Authentication mode:
  2. 打开服务器属性(右键单击根级别对象)。转到“安全”选项卡,然后将“服务器身份验证”模式切换到SQL Server和Windows身份验证模式:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Open the Windows Services program, and find the SQL Server Browser. Open its properties and change the Startup type to automatic:
  2. 打开Windows服务程序,找到SQL Server Browser。打开其属性并将“启动”类型更改为“自动”:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

11.1. Open the Sql Server Configuration Manager program. Navigate to the Protocols under the SQL Server Network Configuration and Enable the TCP/IP option:

11.1。打开Sql Server配置管理器程序。导航到SQL Server网络配置下的协议并启用TCP / IP选项:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

11.2. Open the TCP/IP properties switch to the IP Addresses tab. Make a note of the IP Address field under IP2 (you will need this later):

11.2。打开TCP / IP属性切换到IP地址选项卡。记下IP2下的IP地址字段(稍后需要):

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

11.3. Set the TCP Port under IPALL to 1433:

11.3。将IPALL下的TCP端口设置为1433:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer

  1. Configure the Firewall on the Windows VirtualBox to allow 1433 to be unblocked (I just disabled the whole firewall, probably not the best option):

    在Windows VirtualBox上配置防火墙以允许1433被解除阻塞(我只是禁用了整个防火墙,可能不是最佳选择):

  2. In your Macbook's VirtualBox app, open the settings for the Windows VM and go to the Network tab. Set the Attached to dropdown to NAT, then click Port Forwarding. Add a rule to forward the VM's 1433 port to your localhost's 1433 port. The Guest IP will be the IP from Step 11.2:

    在Macbook的VirtualBox应用程序中,打开Windows VM的设置并转到“网络”选项卡。将Attached to下拉列表设置为NAT,然后单击Port Forwarding。添加规则以将VM的1433端口转发到localhost的1433端口。来宾IP将是步骤11.2中的IP:

如何从我的主机Macbook连接到VirtualBox上运行的SQLServer


You should now be able to connect to your SQLServer from your macbook with a connection string something like this:

您现在应该可以使用以下连接字符串从macbook连接到SQLServer:

jdbc:sqlserver://127.0.0.1;databaseName=testdatabase

JDBC:SQLSERVER://127.0.0.1;的databaseName = testdatabase