以后工作都将与Linux打交道,对于.net忠实粉丝现在进入Linux还算幸运,因为.net core和asp.net core都已经跨平台了。今天没事想试试传说中的Linux Sql server是不是上手容易。
安装SQL Server到Centos 7.3
官方文档:https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat
OS必须条件:
Memory | 3.25 GB |
File System | XFS or EXT4 (other file systems, such as BTRFS, are unsupported) |
Disk space | 6 GB |
Processor speed | 2 GHz |
Processor cores | 2 cores |
Processor type | x64-compatible only |
cat /etc/redhat-release
1,设置yum安装源
curl https://packages.microsoft.com/config/rhel/7/mssql-server.repo > /etc/yum.repos.d/mssql-server.repo
2,安装Mssql server
yum install -y mssql-server
3,查看版本和安装路径
rpm -qa | grep mssql
find / -name mssql
4,配置Sql server管理账户
cd /opt/mssql/bin
./mssql.conf setup (必须停止Mssql-server才能配置)
启动服务
systemctl start mssql-server systemctl enable mssql-server
5,设置防火墙
firewall-cmd --add-port='1433/tcp' --permanent firewall-cmd –reload
安装命令行管理工具
1,安装本地客户端命令行工具
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
yum install -y mssql-tools
2,配置SqlCmd环境变量
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc
3,查看数据库状态
systemctl status mssql-server
如果启动不成功查看日志信息:
journalctl -u mssql-server.service -b
4,连接数据库
sqlcmd -S localhost -U SA -P ''
5,创建数据库并查询
CREATE DATABASE DataTest; GO SELECT Name from sys.Databases; GO
6,一般数据库操作(创建表,插入数据,查询数据)
总结
安装步骤和官方文档的差不多,上手和安装都挺简单的。