Where is mssql_cli installed in the MacOS? - sql-server

So I did this in my M1,
pip3 install mssql-cli
The 2nd time it says:
Requirement already satisfied: mssql-cli in ./Library/Python/3.8/lib/python/site-packages (0.3)
From ls -l ./Library/Python/3.8/lib/python/site-packages/mssql_cli
-rw-r--r-- 1 haha staff 39 Aug 8 17:39 __init__.py
-rw-r--r-- 1 haha staff 2395 Aug 8 17:39 mssql_cli.py
I'm trying to do mssql-cli -S localhost -U haha
zsh: command not found: mssql-cli
Same thing for mssql cmd.
So how should I run it from command line please?

Related

BootstrapSystemDataDirectories() failure (hresult 0x8007010b)

Trying to mount a db into a mssql docker container
Dockerfile
FROM mcr.microsoft.com/mssql/server:2019-latest
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Str0ngP#ssw0rd!
ENV MSSQL_TCP_PORT=1433
EXPOSE 1433
COPY mydb.mdf /var/opt/mssql/data/mydb.mdf
COPY mydb_log.ldf /var/opt/mssql/data/mydb_log.ldf
ENTRYPOINT /opt/mssql/bin/sqlservr
EDIT
It seems that the only thing that prevents the image from running as a container is when I add those two COPY instructions within the Dockerfile. Everything works fine when I remove the two COPY.
In fact, it says that it can't copy c:\tempdata\master.mdf to /var/opt/mssql/data/master.mdf. But why is that?
Lately, when
Structure
All files are in the same folder on my local machine.
myfolder
/Dockerfile
/mydb.mdf
/mydb_log.ldf
Environment
Windows 10 for Workstation
Docker Desktop 4.5.1 (74721) (
Engine 20.10.12,
Compose 1.29.2,
Kubernetes 1.22.5,
Snyk 1.827.0,
Credential Helper 0.6.4)
Visual Studio Code 1.67.2
Error obtained
The image is built in a flawless fashion, letting believe everything's fine. But when I run it, I get an error:
ERROR: BootstrapSystemDataDirectories() failure (HRESULT 0x8007010b)
To run the image, I type the following command:
docker run -p 1433:1433 myimage
or even
docker run myimage
and both fashions creates the same error.
When I type in:
docker images
I can see:
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage latest ffc13a86b57b 28 seconds ago 2.83GB
Which confirms that the image is correctly created.
FINAL EDIT
I thought I would share the resulting Dockerfile and final solution.
The Goal
The goal was to take a client's database MDF and LDF files in SQL Server and mount them in a Docker Container to avoid the process of installing a local SQL Server instance which I don't really need.
Lesson LEARNED
As #AlwaysLearning states, the COPY instructions are processed through the root user of the container, hence taking ownership over the /var/opt/mssql. Doing exactly as she/he said solved the problem. So folder's ownership needs to be given back to mssql user as described in #AlwaysLearning's answer. BIG THX!
Final Solution
The final solution is to be able to mount/attach the client's database files to the containerized instance of SQL Server. For that to work, I needed to write a shell script which does just that.
attach-db.sh
sleep 15s
/opt/mssql-tools/bin/sqlcmd -S . -U sa -P $tr0ngP#ssw0rd! -Q "CREATE DATABASE [mydb] ON (FILENAME = '/var/opt/mssql/data/mydb.mdf'),(FILENAME = '/var/opt/mssql/data/mydb_log.ldf') FOR ATTACH"
This comes from here: Attaching databases via a dockerfile
Dockerfile
FROM mcr.microsoft.com/mssql/server:2019-latest
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=$tr0ngP#ssw0rd!
COPY mydb.mdf /var/opt/mssql/data/mydb.mdf
COPY mydb_log.ldf /var/opt/mssql/data/mydb_log.ldf
COPY attach-db.sh /var/opt/mssql/data/attach-db.sh
ENTRYPOINT /var/opt/mssql/data/attach-db.sh & /opt/mssql/bin/sqlservr
Running the built image
docker run -p 1433:1433 --hostname mydb myimage
Connecting to database
Download and install Azure Data Studio is required to connect to a containerized SQL Server instance.
If you check the logs for the Docker container you'll see that the complete error message is:
2022-06-09 00:12:57.28 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2022-06-09 00:12:57.33 Server ERROR: Setup FAILED copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf': 5(Access is denied.)
ERROR: BootstrapSystemDataDirectories() failure (HRESULT 0x80070005)
This happens because the Dockerfile COPY actions are performed as the root user which leave the file system objects owned by the root user as seen with:
$ ls -la /var/opt/mssql/data
total 12
drwxr-xr-x 1 root root 4096 Jun 9 00:12 .
drwxrwx--- 1 root root 4096 Jun 9 00:12 ..
-rw-r--r-- 1 root root 0 Jun 9 00:06 mydb.mdf
-rw-r--r-- 1 root root 0 Jun 9 00:06 mydb_log.ldf
The SQL Server service itself is executed using the mssql user so now it doesn't have access to the /var/opt/mssql/data directory to add its own files. You can correct that situation by changing the ownership of the files and directories to the mssql user, i.e.:
FROM mcr.microsoft.com/mssql/server:2019-latest
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Str0ngP#ssw0rd!
COPY mydb.mdf /var/opt/mssql/data/mydb.mdf
COPY mydb_log.ldf /var/opt/mssql/data/mydb_log.ldf
USER root
RUN chown -R mssql:root /var/opt/mssql
USER mssql
Now the container will start successfully and you can see that the SQL Server service was able to copy its bootstrap files into the /var/opt/mssql/data directory:
$ ls -la /var/opt/mssql/data
total 81168
drwxr-xr-x 1 mssql root 4096 Jun 9 00:23 .
drwxrwx--- 1 mssql root 4096 Jun 9 00:23 ..
-rw-r----- 1 mssql root 256 Jun 9 00:23 Entropy.bin
-rw-r----- 1 mssql root 4653056 Jun 9 00:23 master.mdf
-rw-r----- 1 mssql root 2097152 Jun 9 00:23 mastlog.ldf
-rw-r----- 1 mssql root 8388608 Jun 9 00:23 model.mdf
-rw-r----- 1 mssql root 14090240 Jun 9 00:23 model_msdbdata.mdf
-rw-r----- 1 mssql root 524288 Jun 9 00:23 model_msdblog.ldf
-rw-r----- 1 mssql root 524288 Jun 9 00:23 model_replicatedmaster.ldf
-rw-r----- 1 mssql root 4653056 Jun 9 00:23 model_replicatedmaster.mdf
-rw-r----- 1 mssql root 8388608 Jun 9 00:23 modellog.ldf
-rw-r----- 1 mssql root 14090240 Jun 9 00:23 msdbdata.mdf
-rw-r----- 1 mssql root 524288 Jun 9 00:23 msdblog.ldf
-rw-r--r-- 1 mssql root 0 Jun 9 00:06 mydb.mdf
-rw-r--r-- 1 mssql root 0 Jun 9 00:06 mydb_log.ldf
-rw-r----- 1 mssql root 8388608 Jun 9 00:23 tempdb.mdf
-rw-r----- 1 mssql root 8388608 Jun 9 00:23 tempdb2.ndf
-rw-r----- 1 mssql root 8388608 Jun 9 00:23 templog.ldf
Edit:
It's worth pointing out that the Dockerfile COPY command can also set owner+group attributes on-the-fly whilst copying files into the image. This then alleviates the need to switch to USER root and back to USER mssql so as to apply chown manually, i.e.:
FROM mcr.microsoft.com/mssql/server:2019-latest
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Str0ngP#ssw0rd!
COPY --chown=mssql:root mydb.mdf /var/opt/mssql/data/mydb.mdf
COPY --chown=mssql:root mydb_log.ldf /var/opt/mssql/data/mydb_log.ldf

get list of preinstalled packages debian 10

Is there a way to list all the packages that were preinstalled in debian 10 before I started installing packages myself, including dependencies etc ? And is there a way to re-initialize debian 10 by removing all these packages ?
Thanks in advance!
Find the oldest apt log file:
$ ls -la /var/log/apt/history.log*
-rw-r--r-- 1 root root 19614 Dec 19 17:09 /var/log/apt/history.log
-rw-r--r-- 1 root root 8570 Nov 29 17:05 /var/log/apt/history.log.1.gz
-rw-r--r-- 1 root root 2573 Oct 23 11:09 /var/log/apt/history.log.2.gz
Find the first package you install manually (use zcat for .gz or cat otherwise):
$ zcat /var/log/apt/history.log.2.gz | grep '^Commandline: apt\(-get\)\? install' | head -1
Commandline: apt install gpm
It seems gpm is the first package I installed manually.
Get the list of all installed packages in chronological order:
$ zcat /var/log/dpkg.log.*.gz | cat - /var/log/dpkg.log | grep ' install ' | sort | awk '{print $4}'
Packages before your first manual package are the ones that were installed by Debian installer. Everything else is what you installed yourself.

Cakephp File permission (Mac os)

The Filelog.php has been chmod 777, but i still get the errors below. How can i fix it? Thanks.... (Mac os)
failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/oven-master/app/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php
-rwxrwxrwx 1 daemon admin 3068 Jul 27 09:49 BaseLog.php
-rwxrwxrwx 1 daemon admin 3088 Jul 27 09:49 ConsoleLog.php
-rwxrwxrwx 1 daemon admin 6370 Jul 27 09:49 FileLog.php
-rwxrwxrwx 1 daemon admin 4570 Jul 27 09:49 SyslogLog.php
You should give permission in logs and tmp those 2 directory recursively.
May be those directory may not exist. Then you have to create in cakephp root and then give permission recursively
I had the same problem:
how i solved it:
open terminal in your cakephp root project folder and type:
sudo bin/cake server

Google AppEngine's dev_appserver.py failing with "invalid command name 'app.yaml'"

From the AppEngine Standard Environment quick-start, I called,
$ dev_appserver.py app.yaml
which failed then returned,
invalid command name 'app.yaml'
I executed the command in the hello_world directory, which holds,
$ ls -l .
total 24
-rw-r--r-- 1 generativist staff 91 Aug 9 06:43 app.yaml
-rw-r--r-- 1 generativist staff 828 Aug 9 06:43 main.py
-rw-r--r-- 1 generativist staff 791 Aug 9 06:43 main_test.py
Google SDK is installed (I use gcloud daily),
$ which dev_appserver.py
/Users/generativist/.external_repos/google-cloud-sdk/bin/dev_appserver.py
Any ideas?
Doh!
Default Python env on this computer is Anaconda 3.6. Creating a new env with python 2.7 and sourceing it fixed the problem.
Thanks for the effort, Dan.

pgbouncer ignores pidfile from ini

trying to start pgbouncer I see in log:
2017-04-25 11:18:06.319 7186 FATAL #src/main.c:612 in function
check_pidfile(): pidfile exists, another instance running?
indeed, it was not deleted by service pgbouncer stop:
[root#b ~]# grep pid /etc/pgbouncer/pgbouncer.ini
pidfile = /pg/pgbouncer/pgbouncer.pid
[root#b ~]# ls -al /pg/pgbouncer/pgbouncer.pid
-rw-r--r-- 1 pgbouncer pgbouncer 5 Apr 25 10:45 /pg/pgbouncer/pgbouncer.pid
because it is hard coded in init:
[root#b ~]# grep ^pid /etc/init.d/pgbouncer
pidfile=/var/run/pgbouncer/pgbouncer.pid
when I change the path to the one I specify in /etc/pgbouncer/pgbouncer.ini it starts working...
Qestion: What do I do to make init.d pickup pid file location from config?
I have:
[root#b ~]# uname -a
Linux 4.9.20-11.31.amzn1.x86_64 #1 SMP Thu Apr 13 01:53:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root#b ~]# pgbouncer -V
pgbouncer version 1.7.2
Installed it with:
wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm
rpm -ivh pgdg-ami201503-96-9.6-2.noarch.rpm
yum install pgbouncer
.

Resources