IT Guy

IT、AI / Machine Learning、IoT、Project Management、プログラミング、ITIL等々

MySQLコマンドメモ書き

背景

何ヶ月に一回しか使わないけど、毎回操作時間より、検索時間がもっとかかる・・・ ということで覚え書き。

ログイン

  • mysql -u root -p

ユーザー操作

現行ユーザー確認
  • SELECT User FROM mysql.user;
ユーザー作成
  • create user <UserName> identified by '<Password>';
実行例
mysql> create user wordpress2 identified by '<Password>';
mysql> SELECT User FROM mysql.user;
+------------+
| User       |
+------------+
| wordpress2 |
| root       |
| root       |
| root       |
| root       |
| wordpress  |
+------------+
6 rows in set (0.00 sec)

データベース操作

現行データベース確認
  • show databases;
データベース作成
  • create database <Database name>;
作成したデータベースにOwner割当
mysql> grant all privileges on wordpress2.* to wordpress2;
データベース削除
  • drop database <Database name>;
実行例
[ec2-user@ip-172-30-1-58 html]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1070
Server version: 5.5.52 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| joomla             |
| mysql              |
| performance_schema |
| wordpress          |
| wordpress2         |
+--------------------+
6 rows in set (0.00 sec)

mysql> drop database joomla;
Query OK, 68 rows affected (0.14 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
| wordpress2         |
+--------------------+
5 rows in set (0.00 sec)

mysql>