如何从主机Macbook连接到VirtualBox上运行的SQLServer [英] How can I connect to SQLServer running on VirtualBox from my host Macbook

查看:286
本文介绍了如何从主机Macbook连接到VirtualBox上运行的SQLServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Mac上运行SQLServer,但不能本地运行.如何使用 VirtualBox 托管SQLServer并从MacBook连接到SQL Server进行本地开发?

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?

推荐答案

  1. 下载 VirtualBox
  2. 此处
  3. 下载Windows 10 ISO
  4. 使用VirtualBox创建新的Windows 10 VM.当它要求虚拟光盘文件"时,将其指向从步骤2下载的ISO:
  1. Download VirtualBox
  2. Download a Windows 10 ISO from here
  3. 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:

  1. 继续Windows 10安装程序
  2. 在Windows VM中,下载并安装SQL Server(我使用 Express )
  3. SQL Server安装完成后,安装我们稍后需要的工具(SSMS)

  1. 使用SSMS,创建一个新数据库(我称为我的testdatabase)

8.1.创建一个新的登录名:右键单击Security > New > Login... 确保选择SQL Server authentication选项.

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

8.2.在Server Roles选项卡中,选择sysadmin选项:

8.2. In the Server Roles tab, select the sysadmin option:

8.3.在User Mapping选项卡中,将登录名映射到数据库,并检查所有分配的角色成员身份:

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

  1. 打开服务器属性(右键单击根级别对象).转到Security选项卡,然后将Server Authentication mode切换为SQL Server and Windows Authentication mode:
  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:

  1. 打开Windows服务程序,然后找到SQL Server Browser.打开其属性,然后将Startup type更改为自动:
  1. Open the Windows Services program, and find the SQL Server Browser. Open its properties and change the Startup type to automatic:

11.1.打开Sql Server配置管理器程序.导航到SQL Server Network Configuration下的Protocols并启用TCP/IP选项:

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.2.将TCP/IP属性开关打开到IP Addresses tab.记下IP2下的IP Address字段(稍后将需要):

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.3.将IPALL下的TCP Port设置为1433:

11.3. Set the TCP Port under IPALL to 1433:

  1. 在Windows VirtualBox上配置防火墙以允许解除阻止1433(我只是禁用了整个防火墙,可能不是最好的选择.) 另一个用户已经在这篇文章的末尾添加了添加防火墙规则的步骤.

在Macbook的VirtualBox应用中,打开Windows VM的设置,然后转到Network选项卡.将Attached to下拉菜单设置为NAT,然后单击Port Forwarding.添加一条规则以将VM的1433端口转发到本地主机的1433端口. Guest IP将是步骤11.2中的IP:

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连接到SQLServer:

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

jdbc:sqlserver://127.0.0.1;databaseName=testdatabase

在Windows防火墙中打开端口以进行TCP访问的步骤

  1. 开始菜单上,单击运行,键入 WF.msc ,然后单击确定".
  2. 具有高级安全性的Windows防火墙的左窗格中,右键单击入站规则,然后在操作窗格(右上角).
  3. 规则类型对话框中,选择端口,然后单击下一步".
  4. 协议和端口对话框中,选择 TCP .选择特定本地端口,然后键入数据库引擎实例的端口号.在我的情况下,我们使用的默认端口为 1433 .单击下一步.
  5. 在"操作"对话框中,选择"允许连接",然后单击下一步".
  6. 个人资料对话框中,我将保持域打开状态,并关闭私有和公共状态.然后单击下一步.
  7. 在"名称"对话框中,键入允许SQL 1433入站",并在说明中输入相同的内容.然后单击完成.
  1. On the Start menu, click Run, type WF.msc, and then click OK.
  2. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane (upper right corner).
  3. In the Rule Type dialog box, select Port, and then click Next.
  4. In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the Database Engine, In my case we are using the default which is 1433. Click Next.
  5. In the Action dialog box, select Allow the connection, and then click Next.
  6. In the Profile dialog box, I am going to Leave Domain turned on and turn private and public off. Then click Next.
  7. In the Name dialog box, type "Allow SQL 1433 Inbound" and for a description I am putting in the same. Then click Finish.

这篇关于如何从主机Macbook连接到VirtualBox上运行的SQLServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆