디렉토리 내 DB 목록을 조회
show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
6 rows in set (0.00 sec)
이름을 지정하여 새로운 DB생성
create database nembizzang; # nembizzang : 데이터베이스 이름
mysql> create database nembizzang;
Query OK, 1 row affected (0.02 sec) # nembizzang DB 생성 완료
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| nembizzang | # nembizzang DB 생성 확인
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
7 rows in set (0.00 sec)
database 사용(이동)
use nembizzang
mysql> use nembizzang;
Database changed
database 삭제
drop database nembizzang;
mysql> drop database nembizzang;
Query OK, 0 rows affected (0.04 sec) # DB 제거 완료
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
6 rows in set (0.00 sec) # DB 제거 확인
mySQL 내 user 조회
use mysql;
select user, host from user;
mysql> use mysql;
Database changed
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
현재 PC에서만 접속 가능한 사용자를 비밀번호와 함께 생성
create user 'nembizzang'@'localhost' identified by '1234';
select host, user from user;
mysql> create user 'nembizzang'@'localhost' identified by '1234';
Query OK, 0 rows affected (0.03 sec) # nembizzang user 생성 완료
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | nembizzang | # nembizzang user 확인
| localhost | root |
+-----------+------------------+
5 rows in set (0.00 sec)
외부에서 접속 가능한 사용자를 비밀번호와 함께 생성
create user 'nembizzang'@'%' identified by '1234';
select host, user from user;
mysql> create user 'nembizzang1'@'%' identified by '1234';
Query OK, 0 rows affected (0.02 sec) # nembizzang1 user 생성 완료
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | nembizzang1 | # nembizzang1 user 확인
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | nembizzang |
| localhost | root |
+-----------+------------------+
6 rows in set (0.00 sec)
📌 host 정보가 다른 user는 id가 동일해도 생성가능
같은 ID의 user여도 접근 경로에 따라 별도로 삭제
DROP USER 'nembizzang'@'localhost';
DROP USER 'nembizzang1'@'%';
SELECT host, user FROM user;
mysql> DROP USER 'nembizzang'@'localhost';
Query OK, 0 rows affected (0.03 sec)
mysql> DROP USER 'nembizzang1'@'%';
Query OK, 0 rows affected (0.04 sec)
mysql> SELECT host, user FROM user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
사용자에게 부여된 모든 권한 목록을 확인
show grants for 'nembizzang'@'localhost';
mysql> show grants for 'nembizzang'@'localhost';
+------------------------------------------------+
| Grants for nembizzang@localhost |
+------------------------------------------------+
| GRANT USAGE ON *.* TO `nembizzang`@`localhost` |
+------------------------------------------------+
1 row in set (0.00 sec)
사용자에게 특정 데이터베이스의 모든 권한을 부여
grant all on testdb.* to 'nembizzang'@'localhost';
show grants for 'nembizzang'@'localhost';
mysql> grant all on testdb.* to 'nembizzang'@'localhost';
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for 'nembizzang'@'localhost';
+----------------------------------------------------------------+
| Grants for nembizzang@localhost |
+----------------------------------------------------------------+
| GRANT USAGE ON *.* TO `nembizzang`@`localhost` |
| GRANT ALL PRIVILEGES ON `testdb`.* TO `nembizzang`@`localhost` |
+----------------------------------------------------------------+
2 rows in set (0.00 sec)
사용자에게서 특정 데이터베이스의 모든 권한을 삭제
revoke all on testdb_* from 'nembizzang'@'localhost';
show grants for 'nembizzang'@'localhost'
mysql> revoke all on testdb.* from 'nembizzang'@'localhost';
Query OK, 0 rows affected (0.04 sec)
mysql> show grants for 'nembizzang'@'localhost';
+------------------------------------------------+
| Grants for nembizzang@localhost |
+------------------------------------------------+
| GRANT USAGE ON *.* TO `nembizzang`@`localhost` |
+------------------------------------------------+
1 row in set (0.00 sec)
수정 내용이 적용되지 않은 경우 새로고침
flush privileges;