sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server.repo
sudo yum update -y
sudo yum install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup
![ Picture description][1]
Ensure that the SA account password slightly meets the default requirements (at least 8 characters, including uppercase and lowercase letters, decimal numbers, and/or non-alphanumeric symbols)
systemctl status mssql-server
![ Picture description][2]
sudo firewall-cmd --zone=public--add-port=1433/tcp --permanent
sudo firewall-cmd --reload
# firewall-cmd is not enabled, no need to do this setting
So far, SQL Server has been running normally on CentOS7
To create a database, you need to use a tool that can run Transact-SQL statements on SQL Server to connect. The following steps install SQL Server command line tools: sqlcmd and bcp
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
sudo yum update
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
sudo yum update
sudo yum install -y mssql-tools unixODBC-devel
echo 'export PATH="$PATH:/opt/mssql-tools/bin"'>>~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"'>>~/.bashrc
source ~/.bashrc
The following steps use sqlcmd to connect locally to a new SQL Server instance
sqlcmd -S localhost -U SA -P '<YourPassword>'
Password input can be interactive
![ Picture description][3]
Create a new database, create a database named
AniuDB
CREATE DATABASE AniuDB
SELECT Name from sys.Databases
GO
in a new line to execute the previous command:GO
![ Picture description][4]
Next create a new table itdevops, and then insert two new rows
AniuDB
database:USE AniuDB
itdevops
:CREATE TABLE itdevops(id INT, name NVARCHAR(50), quantity INT)
INSERT INTO itdevops VALUES(1,'banana',150); INSERT INTO itdevops VALUES(2,'orange',100);
GO
Select data, run query to return data from
itdevops
- Enter a query through the sqlcmd command prompt to return the rows in the
itdevops
table with a number greater than 100
SELECT * FROM itdevops WHERE quantity >100;
# Execute GO
quit
The SQL Server tool on Windows connects to the SQL Server instance on Linux in the same way as connecting to any remote SQL Server instance
SSMS: https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-develop-use-ssms
WP: https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-manage-powershell
SSDT: https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-develop-use-ssdt
Recommended Posts