# Footprinting
scanning MySQL server
```bash
sudo nmap <IP> -sV -sC -p 3306 --script mysql*
```
interaction with the MySQL server
```bash
mysql -u root -h <IP>
mysql -u root -p<password> -h <IP> # no whitespace between -p and password
# ERROR 2026 (HY000): TLS/SSL error: self-signed certificate in certificate chain
mysql -u root -p<password> -h <IP> --skip-ssl
```
# DB Dump
```bash
# 데이터베이스 전체 덤프
mysqldump -u <유저이름> -p'<비밀번호>' -P <포트> -h <ip> <데이터베이스>
# 테이블 덤프
mysqldump -u <유저이름> -p'<비밀번호>' -P <포트> -h <ip> <데이터베이스> <테이블이름>
# 특정 레코드 덤프 - 예) username 열에 admin 문자열이 들어간 레코드만 덤프
mysqldump -u <유저이름> -p'<비밀번호>' -P <포트> -h <ip> <데이터베이스> <테이블이름> --where="username LIKE '%admin%'"
# 예시 - production 데이터베이스에 users 테이블 모두 덤프
mysqldump -u root -p'root' -h 172.31.244.116 -P 33060 production users > user.sql.dump
# 예시 - production 데이터베이스의 users 테이블에 username 열 중에서 davis 라는 문자열이 포함된 레코드만 덤프
mysqldump -u root -p'root' -h 172.31.244.116 -P 33060 production users --where="username LIKE '%davis%' " > davis.dump
```
# Commands
| **Command** | **Description** |
| ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `mysql -u <user> -p<password> -h <IP address>` | Connect to the MySQL server. There should **not** be a space between the '-p' flag, and the password. |
| `show databases;` | Show all databases. |
| `use <database>;` | Select one of the existing databases. |
| `show tables;` | Show all available tables in the selected database. |
| `show columns from <table>;` | Show all columns in the selected table. |
| `select * from <table>;` | Show everything in the desired table. |
| `select * from <table> where <column> = "<string>";` | Search for needed `string` in the desired table. |