ติดตั้ง SQL Server 2017 บน CentOS 7

Install SQL Server 2017

1.Download the Microsoft SQL Server 2017 Red Hat repository configuration file:

sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo

2.Run the following commands to install SQL Server:

sudo yum install -y mssql-server

3.After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

4.Once the configuration is done, verify that the service is running:

systemctl status mssql-server

5.To allow remote connections, open the SQL Server port on the firewall on RHEL. The default SQL Server port is TCP 1433. If you are using FirewallD for your firewall, you can use the following commands:

sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload

Install the SQL Server command-line tools

1.Download the Microsoft Red Hat repository configuration file.

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

2.If you had a previous version of mssql-tools installed, remove any older unixODBC packages.

sudo yum remove unixODBC-utf16 unixODBC-utf16-devel

3.Run the following commands to install mssql-tools with the unixODBC developer package. For more information, see Install the Microsoft ODBC driver for SQL Server (Linux).

sudo yum install -y mssql-tools unixODBC-devel

4.For convenience, add /opt/mssql-tools/bin/ to your PATH environment variable. This enables you to run the tools without specifying the full path. Run the following commands to modify the PATH for both login sessions and interactive/non-login sessions:

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

Connect locally

1.Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P).

sqlcmd -S localhost -U SA -P '<YourPassword>'

Create and query data

Create a new database

1.From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:

CREATE DATABASE TestDB

2.On the next line, write a query to return the name of all of the databases on your server:

SELECT Name from sys.Databases

3.The previous two commands were not executed immediately. You must type GO on a new line to execute the previous commands:

GO

Exit the sqlcmd command prompt

QUIT