LoginSignup
11
9

More than 5 years have passed since last update.

UbuntuサーバにMySQLクライアント(mysql-clientのmysqlコマンド)をインストールする

Posted at

はじめに

Ubuntu Server 14.04 LTSサーバに対して、MySQLクライアント(mysql-clientパッケージのmysqlコマンド バージョン5.5.41)をインストールする手順です。

対象環境

MySQLクライアント(mysqlコマンド)をインストールする環境です。

・64bit版 Ubuntu Server 14.04 LTS (3.13.0-44-generic)

Ubuntuサーバに対するMySQLクライアントインストール手順

(1) Ubuntuサーバにログインし、root権限を持つユーザにスイッチします。

ubuntu@example-ubuntu-server:~$ sudo su -
sudo: unable to resolve host example-ubuntu-server
root@example-ubuntu-server:~#

root@example-ubuntu-server:~# id
uid=0(root) gid=0(root) groups=0(root)
root@example-ubuntu-server:~#

(2) UbuntuサーバにMySQLクライアント(mysqlコマンド)をインストールします。

root@example-ubuntu-server:~# uname -a
Linux example-ubuntu-server 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
root@example-ubuntu-server:~#
root@example-ubuntu-server:~# apt-get -y install mysql-client

  (中略)
The following NEW packages will be installed:
  libdbd-mysql-perl libdbi-perl libmysqlclient18 libterm-readkey-perl
  mysql-client mysql-client-5.5 mysql-client-core-5.5 mysql-common
  (中略)

Setting up mysql-client-5.5 (5.5.41-0ubuntu0.14.04.1) ...
Setting up mysql-client (5.5.41-0ubuntu0.14.04.1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.5) ...
root@example-ubuntu-server:~#

(3) MySQLクライアント(mysqlコマンド)がインストールされた事を確認します。

root@example-ubuntu-server:~# which mysql
/usr/bin/mysql

root@example-ubuntu-server:~# mysql --version
mysql  Ver 14.14 Distrib 5.5.41, for debian-linux-gnu (x86_64) using readline 6.3
root@example-ubuntu-server:~#

(4) Ubuntuサーバにインストールしたmysqlコマンドを実行し、MySQLサーバへ接続出来るかテストします。

root@example-ubuntu-server:~# mysql -u [MySQLユーザ名] --password="[MySQLユーザのパスワード]" -h [MySQLサーバのIPアドレス] example_schema

 (中略)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| example_schema     |
+--------------------+
2 rows in set (0.00 sec)

mysql>
mysql> SELECT * FROM `example_schema`.`example_table`;
+------+------+
| id   | name |
+------+------+
|    1 | test |
|    2 | test |
+------+------+
2 rows in set (0.19 sec)

mysql> INSERT INTO `example_schema`.`example_table`( id, name ) VALUES( 3, 'test' );
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM `example_schema`.`example_table`;
+------+------+
| id   | name |
+------+------+
|    1 | test |
|    2 | test |
|    3 | test |
+------+------+
3 rows in set (0.01 sec)

mysql> \q
Bye
root@example-ubuntu-server:~#

MySQLサーバへ接続出来れば、Ubuntuサーバへのmysqlコマンドのインストールは完了です。


以上になります。

11
9
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
11
9