서버/MySQL 2018. 2. 27. 18:59

MySQL- 2. MySQL 접속 및 DB 생성

 

 

 

1. 'root' 계정으로 mysql를 접속한다. (초기 설치시 'root' 계정의 패스워드 없다.)

 

msfadmin@metasploitable:~$ mysql -u root -p
Enter password:  (엔터)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.51a-3ubuntu5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

 

 


2. DB 생성 및 삭제 방법

 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| dvwa               |
| metasploit         |
| mysql              |
| owasp10            |
| tikiwiki           |
| tikiwiki195        |
+--------------------+
7 rows in set (0.00 sec)

 

 

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

 

 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| dvwa               |
| koreaisit          |
| metasploit         |
| mysql              |
| owasp10            |
| tikiwiki           |
| tikiwiki195        |
+--------------------+
8 rows in set (0.00 sec)

 

 

mysql> drop database koreaisit;
Query OK, 0 rows affected (0.01 sec)

 

 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| dvwa               |
| metasploit         |
| mysql              |
| owasp10            |
| tikiwiki           |
| tikiwiki195        |
+--------------------+
7 rows in set (0.00 sec)

 

 

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

 


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cisco              |
| dvwa               |
| metasploit         |
| mysql              |
| owasp10            |
| tikiwiki           |
| tikiwiki195        |
+--------------------+
8 rows in set (0.00 sec)

 

 

mysql> use cisco;
Database changed

 

 

mysql> select database();
+------------+
| database() |
+------------+
| cisco      |
+------------+
1 row in set (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

 


3. 사용자 계정 추가 및 특정 DB 권한 할당

 

mysql> create user ccna1234@localhost identified by '1234';
Query OK, 0 rows affected (0.00 sec)

 

 

mysql> grant all on cisco.* to ccna1234@localhost;
Query OK, 0 rows affected (0.00 sec)

 

 

mysql> quit
Bye

 


msfadmin@metasploitable:~$ mysql -u ccna1234 -p1234
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.51a-3ubuntu5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

 

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

 


mysql> quit
Bye


msfadmin@metasploitable:~$

 

 


4. 사용자 계정 삭제


msfadmin@metasploitable:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.51a-3ubuntu5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

 

 

mysql> select user from user;
+------------------+
| user             |
+------------------+
| debian-sys-maint |
| guest            |
| root             |
| ccna1234         |
+------------------+
4 rows in set (0.00 sec)

 

 

mysql> delete from user where user='ccna1234';
Query OK, 1 row affected (0.00 sec)

 

 

mysql> drop user ccna1234@localhost;
Query OK, 0 rows affected (0.00 sec)

 

 

mysql> select user from user;
+------------------+
| user             |
+------------------+
| debian-sys-maint |
| guest            |
| root             |
+------------------+
3 rows in set (0.00 sec)

 

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

 


5. 원격 접속 계정 생성 및 모든 권한 할당

 

mysql> grant all privileges on *.* to ccna1234@'%' identified by '1234';
Query OK, 0 rows affected (0.00 sec)

 

 

mysql> select user from user;
+------------------+
| user             |
+------------------+
| debian-sys-maint |
| ccna1234         |
| guest            |
| root             |
+------------------+
4 rows in set (0.00 sec)

 

 

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 


mysql> exit
Bye

 

 

msfadmin@metasploitable:~$ mysql -h 192.168.20.204 -u ccna1234 -p1234
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.0.51a-3ubuntu5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cisco              |
| dvwa               |
| metasploit         |
| mysql              |
| owasp10            |
| tikiwiki           |
| tikiwiki195        |
+--------------------+
8 rows in set (0.00 sec)

 

 

mysql> quit
Bye

Posted by 김정우 강사(카카오톡 : kim10322)
,


Q