Home > database >  I want to create sample database fpr Sql server on Kubernetes
I want to create sample database fpr Sql server on Kubernetes

Time:12-10

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

CodePudding user response:

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.

enter image description here

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