1-1.MySQLにログインする方法。MySQLモニタで接続する2つの方法。

2019年7月15日

MySQLを使う一番基本的な方法として「MySQLモニタ」があります。
これはコマンドによる対話形式のツールです。
MySQLをインストールすると使えるようになっています。
GUIで様々な管理が出来る標準ツール「MySQL Workbench」もありますが、まずはMySQLモニタをマスターするのがちゃんと仕組みを理解するにはおすすめです。
本記事ではWindowsで説明していますがMySQLモニタの基本的な使い方は他のOSでもほとんど共通です。

目次

1.MySQLモニタでログインする手順

前述の通りMySQLを操作するにはコマンドベースのツールである「MySQLモニタ」を使用します。

1)コマンドプロンプトの起動

MySQLモニタは前述のとおりコマンドベースですのでコマンドプロンプトで実行されます。
まずは「スタート」→「Windowsシステムツール」→「コマンドプロンプト」を起動してください。

2)MySQLモニタでログインする(パスワードは別入力する方法)

コマンドプロンプトで以下のコマンドを入力してMySQLに接続します。
-pをつけるとエンターキーを押した後にパスワードの入力を求められます。

mysql -u root -p
ここでパスワードを入力する

実行例)

C:¥>mysql -u root -p
Enter password: ****       ←【ここでパスワードを入力します】
Welcome to the MySQL monitor. Commands end with ; or ¥g.
Your MySQL connection id is 2
Server version: 5.6.35-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '¥h' for help. Type '¥c' to clear the current input statement.

mysql>

3)MySQLモニタでログインする(パスワードを引数で入力する方法)

パスワードをコマンドラインで直接記述することも可能です。
-pに空白を空けずに入力します。
この場合人目に触れないように気を付けてください。
正常に接続出来ると「mysql>」のプロンプトが表示されます。

実行例)ユーザーがrootでパスワードがpasswdの場合

C:¥>mysql -u root -ppasswd
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or ¥g.
Your MySQL connection id is 3
Server version: 5.6.35-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '¥h' for help. Type '¥c' to clear the current input statement.

mysql>