文書更新:2018年07月08日(日) 午後5時03分55秒

Home > 備忘録 > MySQL に関すること > データベースへ接続( 93 )

MySQLにログイン

[root@server]# mysql -u root -p	←root権限でログイン
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 888
Server version: 5.5.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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をログアウト

  1. exitコマンドでログアウト
  2. mysql> exit
    Bye
    [root@server]# 	←ログアウトできた状態
  3. quitコマンドでログアウト
  4. mysql> quit
    Bye
    [root@server]# 	←ログアウトで1きた状態

ユーザーの登録

mysql> grant all privileges on demo.* to fedora@localhost identified by 'kokohorewanwan';	←demoデータベースへの全てのアクセス権限を持った、パスワード'kokohorewanwan'をもった新規ユーザーfedoraを登録
mysql>

ユーザーの確認

mysql> select user,host,password from mysql.user;
+--------+-------------+-------------------------------------------+
| user   | host        | password                                  |
+--------+-------------+-------------------------------------------+
| root   | localhost   | ***************************************** |
| root   | leom.mydns.jp | ***************************************** |
| root   | 127.0.0.1   | ***************************************** |
| root   | ::1         | ***************************************** |
| fedora | localhost   | ***************************************** |
+--------+-------------+-------------------------------------------+
5 rows in set (0.34 sec)

mysql>

ユーザーの削除

mysql> delete from mysql.user where user='fedora';
Query OK, 1 rows affected (0.00 sec)

mysql>

データベースの作成

mysql> create database demo;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;	←作成の確認
+--------------------+
| Database           |
+--------------------+
| information_schema |
| demo               |
+--------------------+
2 rows in set (0.00 sec)

mysql>

データベースの削除

mysql> drop database demo;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;	←削除の確認
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 rows in set (0.00 sec)

mysql>