今日の人気記事

  1. MySQLのダウンロードとインストール - Windows環境

MAMPのMySQLをコマンドラインで操作 - Macターミナル - MAMPの使い方

当ページのリンクには広告が含まれています。

スポンサーリンク

MAMP の MySQL をコマンドラインで操作する方法を解説します。

mamp-mysql-command-line
まずは、MAMPを起動します。

mamp-mysql-command-line-0
Finderを起動し、「アプリケーション」→「ユーティリティ」にアクセスし、「ターミナル」を起動します。

MAMPのコマンド群は「/Applications/MAMP/Library/bin/」に格納されているので、「cdコマンド」で作業ディレクトリを移動します。

$ cd /Applications/MAMP/Library/bin/
スポンサーリンク

MySQLをコマンドラインで操作

mysqlコマンドを実行します。

$ ./mysql -u root -p
Enter password: ← パスワードを入力します。
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.29 Source distribution

Copyright (c) 2000, 2012, 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> 

MySQLのプロンプト(mysql>)が表示されれば、OKです。MySQLに接続成功です。以下のようにコマンドを実行してみましょう。

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| performance_schema |
| wordpress          |
+--------------------+
3 rows in set (0.00 sec)

MAMPのMySQLにあるデータベースが表示されれば、OKです。

パスを通す

毎回、作業ディレクトリを移動したり、./mysqlと実行するのはめんどうなのでパスを通します。ユーザーのホームディレクトリにある不可視ファイル~/.bash_profileに以下のコードを追加します。

export PATH=$PATH:/Applications/MAMP/Library/bin

ターミナルを再起動するか以下のコマンドを実行し、設定を反映します。

$ source .bash_profile

適切にパスが通ったかを確認します。

$ mysql -u root -p

これでMySQLに接続できれば、OKです。

スポンサーリンク

関連記事(一部広告含む)