简体   繁体   中英

How to connect SQL Server on mac

I am using Azure Data Studio as software and it is impossible to connect SQL Server even with Windows Authentication. The process returns this error:

这个

But when i'm trying to connect via SQL login, program wants a username and password. I don't know where can I get them.

If you use Docker, you can get a SQL Server image and run it locally. This allows you to connect to your SQL Server instance using Azure Data Studio.

First, pull the image

sudo docker pull mcr.microsoft.com/mssql/server:2017-latest

Then, run it

sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong:Passw0rd' \ -p 1433.1433 --name sql1 \ -d mcr.microsoft:com/mssql/server:2017-latest

Note: "The password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols" This is important. SQL Server won't start otherwise.

Check if it is up and running

docker ps -a

You will see the status column telling you how long it's been up

Finally, open up Azure Data Studio, plug in these values, and click 'Connect':

  • Server: localhost
  • Username: sa
  • Password: The password you used in Step 2
  • Authentication Type: Select SQL Login
  • Go to Advanced
  • Port: 1433

Hope this helps.

Even I was getting the same Error with Azure Data Studio. That is coming up because you need Docker to run along with the Azure Data Studio. Per your post, i am not sure if you have installed docker or is your docker running in the background while you try to connect to the server(if docker is already installed).

In order to connect to a server, you need to go to preferences of your Docker settings and increase the Memory allocation from the default of 2GB to minimum 4GB (as SQL server needs min 3.25GB space). Save and restart the docker.

Once restarted, all you need to do is pull the docker image of the sql server and download it. this can be done by below commands on your terminal. FYI, I am using bash commands below:

Command 1:

sudo docker pull mcr.microsoft.com/mssql/server:2017-latest

This will pull the latest vesion docker image and download. Once done, you need to set your SQL authentication on the server for your database. Follow below commands:

Command 2:

    sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<SetYourPasswordHere>' \
   -p 1433:1433 --name sql1 \
   -d mcr.microsoft.com/mssql/server:2017-latest

This sets your password and uses the port 1433 for SQL server (which is the default port). To confirm if the image has been created and the SQL server is running on docker, execute the below command to check log(s).

Command 3:

docker ps

To check all instances in your history of dockers( ie if you already had dockers installed before you are attempting this SQL connection/execution), run the below command and it will give you all the logs of all instances you have created

Command 4:

docker ps -a 

or

docker ps -all

Once, you have completed above steps and see that the docker has created SQL instance, you need to go to Azure Data Studio and set the below credentials to access the server that you just created above using Docker.

Server: localhost
Authentication Type: SQL Authentication
Username: sa
Password: <Check Command 2 to see what you entered in the password where it says SetYourPasswordHere>

Hope this helps in your tryst with running SQL server on your MAC. All the Best!

You can't log in with Windows Authentication via mac. Windows Authentication is Windows Authentication. When you trying to connect SQL server with Windows Authentication via mac, data studio tries to use your mac log in properties and it cannot be the same as the windows server you want to connect to. If you want to log in SQL server via mac with data studio, you need to know a SQL server user and its password.

In your screenshot, it seems that you are trying to connect to your localhost machine.

Please ensure you have successfully installed SQL Server on your local machine. The local port 1433 shall be listened by the SQL Server process.

The error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server

Means that you cannot connect to the target machine. It wasn't that you are connecting with a wrong key or authentication mode.

Of course, you can NOT use Windows Integrated Authentication in Mac. Try to contact the person who prepared your SQL Server instance and get the password of it.

For those who come upon this question, yes, you can in fact log on to Azure Data Studio with integrated authentication from a Mac. If your Mac is joined to the domain, it will work without a hitch. if not, follow this guy's clear and concise method to make it work. https://port1433.com/2019/04/04/using-ad-authentication-in-azure-data-studio-on-a-non-windows-non-domain-machine/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM