CentOSにインストールしたMySQLを操作するコマンドのメモです。
MySQLのrootユーザーでログインする
mgate | CentOSのユーザー名 |
---|---|
centos01 | CentOSのサーバー名 |
root | MySQLにアクセス権限を持つユーザー名。 root以外のユーザーでアクセスするときには、rootを異なるユーザーに置き換える。 |
[mgate@centos01 ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4455
Server version: 5.1.69 Source distribution
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4455
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, 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>
testデータベースに対して全権限のあるユーザーを作成
test | データベース名 |
---|---|
testuser | 作成するユーザー名 |
testpass | 作成するユーザーのパスワード |
mysql> grant all privileges on test.* to testuser@localhost identified by 'testpass';
mysqlに登録されているユーザーを表示
mysql> select user from mysql.user;
ログインしているユーザーに権限のあるデータベース一覧を表示
mysql> show databases;
ユーザーとアクセス可能なホストを一覧表示
※rootでログインしてから実行
mysql> select user, host from mysql.user;
+------------+-----------+
| user | host |
+------------+-----------+
| root | 127.0.0.1 |
| testuser | localhost |
| root | localhost |
+------------+-----------+
+------------+-----------+
| user | host |
+------------+-----------+
| root | 127.0.0.1 |
| testuser | localhost |
| root | localhost |
+------------+-----------+
アクセス可能なホストを追加
test | データベース名 |
---|---|
testuser | 作成するユーザー名 |
testpass | 作成するユーザーのパスワード |
% | ワイルドカード 今回はどのホストからでもアクセスできるように設定 |
mysql> grant all privileges on test.* to testuser@"%"
-> identified by 'testpass' with grant option;
-> identified by 'testpass' with grant option;