0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

snowflakeに設定ファイル使ってCUIで(snowsql)ログインする

Posted at

背景

snowflakeをGUIベースで実行するのが面倒くさいと思った。
CUIでどうやってやるのか聞かれるのが面倒になったのでにコマンドラインベースでやるメモ。
設定ファイルあり、なしと複数の設定を切り替えてログインするまで。
仕事で使っている人も多いと思うのでプロキシ設定忘れないように!!

あと、Windowsでやってます。

準備

標準のガイドを見ながらsnowsqlをインストール。面倒であれば、リポジトリから直接ファイルを落としてインストール。

アカウント名とユーザー名とパスワードを思い出しておく。
尚、アカウント名はsnowflakeのURLが「https://x12345.ap-northeast-1.aws.snowflakecomputing.com/」だとしたら
「.snowflakecomputing.com」までの部分アカウント名であり「x12345.ap-northeast-1.aws」となる

手始めに設定ファイルなしでsnowflakeにCUI経由でログイン

コマンドプロンプトでアカウント名、ユーザー名、を引き数に実行する。
$ snowsql -a アカウント名 -u ユーザー名

その後パスワードを聞かれるので、入力するとログインできる。
スクリーンショット 2021-06-22 211152.png

プロキシいる場合

環境変数に「HTTP_PROXY」「HTTPS_PROXY」を設定する。
もしくはコマンドで次のものを実行してもよい。
ただ、下記に書いている設定ファイル経由でプロキシ設定したほうが利便性が高いと思う。

例(パスなしの場合は、@以降だけの「プロキシURL:ポート番号」でOK):

set HTTP_PROXY=http://username:password@proxyserver.com:8080
set HTTPS_PROXY=http://username:password@proxyserver.com:8080

設定ファイルありでsnowflakeにCUI経由で自動ログイン

「c:\ユーザー\ユーザー名\.snowsql」にある次の場所のconfigをメモ帳などで開く。

スクリーンショット 2021-06-22 212317.png

[connections]の次の部分を書き直す。

[connections]          
# *WARNING* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING*
# 
# The Snowflake user password is stored in plain text in this file.
# Pay special attention to the management of this file.
# Thank you.
# 
# *WARNING* *WARNING* *WARNING* *WARNING* *WARNING* *WARNING*

# If a connection doesn't specify a value, it will default to these
#
# accountname = defaultaccount  
# region = defaultregion
# username = defaultuser
# password = defaultpassword
# dbname = defaultdbname
# schemaname = defaultschema
# warehousename = defaultwarehouse
# rolename = defaultrolename
# proxy_host = defaultproxyhost
# proxy_port = defaultproxyport

↓ファイルを上書きする。こんな感じ。

[connections]          
accountname = アカウント名
username = ユーザー名
password = パスワード

そうすると次のコマンドをコマンドプロンプトで実行するだけでログインできる。
もちろんプロキシが必要な場合は「proxy_host = roxyserver.com」「proxy_port = 8080」みたいな感じでconnectionsにホストとポートを追記すること。

$snowsql

設定ファイルを切り替えながらsnowflakeにCUI経由でログイン

自分みたいに、複数のsnowflakeアカウントを持っているときに自動ログインだけで足りないときは、
設定ファイルに「connections.名前」みたいなものを複数追加できる。

[connections.sample1]          
accountname = アカウント名
username = ユーザー名
password = パスワード

[connections.sample2]          
accountname = アカウント名
username = ユーザー名
password = パスワード

[connections.sample3]          
accountname = アカウント名
username = ユーザー名
password = パスワード

コマンドプロンプトからの実行時に「snowsql -c 名前」で設定ファイルを切り替えてログインできる。
[connections.sample3]を使う場合はこんな感じ。

$snowsql -c sample3

本家の説明書き

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?