I deployed sql server 2017 to my kubernetes and I want to put it a sample db such as northwind. There is no a gui for manage sql server. How Can I do that?
You can forward your sql server port to localhost and then connect to the database using SQL Server Management Studio.
kubectl port-forward <sql-pod-name> <localhost-port>:<mssql-port>
For example:
kubectl port-forward mssql-statefulset-0 1433:1433
Then your database would be accessed on localhost.
Note that there is a comma between the address and the port.
If you manage to connect successfully, you can manually create the database using the SQL Server Management Studio tool.
Another way is to connect directly to your database container inside a pod using exec command and then execute sqlcmd commands.
kubectl exec -it <pod-name> -- /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SA-password'
Or just like this
kubectl exec -it <pod-name> -- /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SA-password' -Q 'CREATE DATABASE <database-name>'
Related
I am using docker images from this github: https://github.com/oracle/docker-images
I installed oracle db version 19c in my environment with the following command:
docker run --name oracle19c --network host -p 1521:1521 -p 5500:5500
-v /opt/oracle:/u01/oracle oracle/database:19.3.0-ee
Then I connect to it to run sqlplus with:
docker exec -ti oracle19c sqlplus system/oracle#orclpdb1
SQL>
Then I managed to successfully load some data into it. However, I would like to connect to the database with an ODBC connection. However, I am confused on going about and connecting to the database inside docker, I have not been able to find any resources or guides. The server runs Ubuntu and I am connected over an ssh connection if that helps.
Edit:I tried with unixodbc but I would be willing to switch over to any other available options.
My Docker linux SQL Server is not working today at my machine.
I am not sure if this is firewall (I have off them all), or Docker settings (as I just upgraded to the latest Docker version), or a Docker SQL Server issue (but this was working fine on the same machine earlier).
Could anyone help?
I have tried using bash,
/opt/mssql-tools/bin/sqlcmd -S localhost,8010 -U SA -P Test123!
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
The docker compose file
version: '3'
services:
mssql:
network_mode: lsvc
image: microsoft/mssql-server-linux:2017-latest
container_name: mssql
hostname: mssql
volumes:
- ./.db:/var/opt/mssql/
- /var/opt/mssql/data
- ./sqlinit.sql:/scripts/sqlinit.sql
ports:
- 8010:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Test123!
command:
- /bin/bash
- -c
- |
# Launch MSSQL and send to background
/opt/mssql/bin/sqlservr &
# Wait for it to be available
echo "Waiting for MS SQL to be available"
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , ##servername"
is_up=$$?
while [ $$is_up -ne 0 ] ; do
echo -e $$(date)
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , ##servername"
is_up=$$?
sleep 1
done
# Run every script in /scripts
# TODO set a flag so that this is only done once on creation,
# and not every time the container runs
#for foo in /scripts/*.sql
/opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P Test123! -l 30 -e -i /scripts/sqlinit.sql
#done
# So that the container doesn't shut down, sleep this thread
sleep infinity
I would suspect that the mssql instance had failed to start.
Looking at your docker file when the server fail to start it runs into in infinite loop. I would advice you to limit the number of retries on the loop so you will have an indication that the server is failing on startup.
Or better consider the use of the HEALTHCHECK option and not the loop script
see https://blog.couchbase.com/docker-health-check-keeping-containers-healthy/
To troubleshooting the problem try
docker logs <mssql-container-id>
if this doesn't provide enough information try connecting to the container as this was a simple machine.
docker exec -it <mssql-container-id> bash
Look for errors in /var/opt/mssql/log/errorlog
See https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-troubleshooting-guide?view=sql-server-ver15
i found the root cause, it is not due to docker mssql linux
but the latest Docker Desktop Community 2.2.0.0
after uninstall it then downgrade to old version, Docker Desktop Community 2.1.0.5.
it is working now, connect to mssql success.
not sure what is new in latest docker desktop, anyway...i will use old version now.
also one important point to take note, the ".db" folder (windows path where the yml file reside), must deleted before build the docker image.
I've created a docker container using the following command:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=MyStr#ngPassw0rd' -e 'MSSQL_PID=Express' -p 1433:1433 -d microsoft/mssql-server-linux:latest
I'd like to use SSMS to connect to this database from my host machine.
Which parameters should I use in the SSMS login dialog?
My current entries:
Server type: Database Engine
Server name: [machine-name]
Authentication: SQL Server authentication
Login: sa
Password: MyStr#ngPassw0rd
But I'm getting this error:
TITLE: Connect to Server
Cannot connect to localhost:.
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
network path not found
Seems I'm not able to 'see' the database.
Is there something wrong with my connection string or is it not possible to connect this way?
If you are using Docker CE on Windows with Linux containers, specify double-quotes around the environment variables so that they are recognized:
docker run -e "ACCEPT_EULA=Y" -e 'SA_PASSWORD=MyStr#ngPassw0rd" -e "MSSQL_PID=Express" -p 1433:1433 -d microsoft/mssql-server-linux:latest
You will then be able to connect using SSMS. With the default 1433 port in this case, you can specify . or localhost as the server name. You can also connect to the container instance from a remote host specifying only your machine name (assuming firewall rules allow incoming port 1433 traffic).
With single-quotes, the values are not recognized and the container will immediately stop. You can use docker logs <container-name> to view messages from the SQL Server error log for troubleshooting. Below is an example using an explict container name (which I recommend to facilitate tasks like this) using your original problem command:
docker run --name sql1 -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=MyStr#ngPassw0rd' -e 'MSSQL_PID=Express' -p 1433:1433 -d microsoft/mssql-server-linux:latest
c3de002fc22106e53c9b165c7f444905b5ef1bb1596eddf1b097cdd6d60e6c75
docker logs sql1
The SQL Server End-User License Agreement (EULA) must be accepted
before SQL Server can start. The license terms for this product can be
downloaded from http://go.microsoft.com/fwlink/?LinkId=746388.
You can accept the EULA by specifying the --accept-eula command line
option, setting the ACCEPT_EULA environment variable, or using the
mssql-conf tool.
As you can see from the logged message, the SQL instance stopped (stopping the container) because the SQL Server did not recognize the EULA was accepted due to the single quotes.
I can connect to SQL Server in a Docker container using...
Docker exec -it 93fc /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password$$123
But I can't connect if I plug the same details into RazorSQL.
i.e. localhost with SA and Password$$123
What step am I missing?
This is the run command...
Docker run -e 'ACCEPT_EULA=Y' -e SA_PASSWORD=Password$$123 -p 1433:1433 -d microsoft/mssql-server-linux
This is a connection string I've tried from a test running in Visual Studio...
Data Source=localhost;Initial Catalog=master;User=sa;Password=Password$$123;
I think it can find the SQL Server but for some reason it can't login with SA.
Even this running from Windows doesn't work...
sqlcmd -S 192.168.10.79,1433 -U SA -P Password$$123
This problem goes away if I update the password using...
ALTER LOGIN SA WITH PASSWORD='Pa$$word123'
So I can connect to SQL Server inside the container using the initial password and then if I change the password I can connect externally.
How can the password determine if an external connection works?
If I enter env in the console, I get...
MSSQL_SA_PASSWORD=Password14961123
I presume that was auto generated.
I am trying to connect to a remote database using sqlcmd. I have tried something like this
sqlcmd -U <ComputerName>\Administrator -P adminpassword -S *.*.*.* -d mydatabase
But this is causing an error:
Failed to Login failed for user '\Administrator'
If I log onto the server where my database and run the command, it won't let me log in, either. But if I go into my SQL Server database and create a SQL Server user and run the same command with those details, I can log in.
But what I want to do is log in via the Administrator user from a different machine. Does anyone see what I'm doing wrong?
With Windows credentials you should use -E:
sqlcmd -E -S *.*.*.* -d mydatabase