0

I installed an mssql server using docker container in an ubuntu EC2 as follows:

sudo docker run --name my_mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<mypassword>" -p 1433:1433 -v /home/ubuntu/db:/var/opt/mssql -d microsoft/mssql-server-linux
sudo netstat -lpnt |grep 1433

shows 1433 is listening

I can login the mssql server using username=sa and password=mypassword using SQLPRO for MSSQL – a database manager, I can then create a database from that manager.

However, if I operate the mssql server from the EC2 in which the mssql server is installed, using the below command,

mysql -h <EC2 IP> -P 1433 -u sa -p

and then provide the password, it just stuck there and finally stop connecting with error message:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2

Why I cannot operate mssql server from the ubuntu EC2? How can I do that?

user389955
  • 9,605
  • 14
  • 56
  • 98
  • `MySQL` is one product, `SQL Server` is another. You can't use `mysql` to connect to SQL Server any more than you can use it to connect to Oracle, DB2, PostgreSQL or SQLite – Panagiotis Kanavos Jun 30 '20 at 07:05

2 Answers2

3

You DB server is MSSQL, and you are trying to connect with MSSQL using Mysql client, which will defiantly not work.

Can I use mysql to connect to SQL Server?

microsoft/mssql-server-linux

you can verify accessibility using

telnet EC2_IP 1433

or you can use sqlcmd or MSSQL client to connect with your DB container.

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • 1
    Thanks I now realized the command I use to connect mssql server is mysql, I thought it was mssql. these two words look so similar. Thanks I have install sqlcmd and use it to login the mssql server. – user389955 Jun 30 '20 at 17:35
2

You're using SQL Server, not MySQL. You can't use another database's tools to connect to it.

You need to use SQL Server's command-line tools:

  • sqlcmd is the CLI query tool, similar to mysql
  • bcp is used for bulk import/export

You can also use Azure Data Studio (the unfortunate marketing name of what started as SQL Server Operations Studio). ADS can connect to SQL Server directly and PostgreSQL through an extension

It's a cross-platform editor/IDE similar to Visual Studio Code built for querying, visualizing results, managing databases and executing Python scripts and Jupiter Notebooks. It comes with server and database dashboards out of the box. There are several extensions for advanced monitoring and troubleshooting too.

It's also trivial to create new dashboards based on your own queries: Just copy the visualisations JSON definition into a settings file.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Thanks I now realized the command I use to connect mssql server is mysql, I thought it was mssql. these two words look so similar. Thanks I have install sqlcmd and use it to login the mssql server. – user389955 Jun 30 '20 at 17:35