## MySQL Introduction - open source SQL rdbms supported by Oracle that uses the SQL database language - MariaDB is a fork of MySQL - consists of a server (i.e., the rdbms) and one or more clients - data stored in tables with different columns, rows, and data types - most important databases: system sceham (sys) and information schema (information_schema) - mySQL is ideally suits for apps such as dynamic websites - LAMP: linux, apache, mysql, php - LEMP: linux, nginx, mysql, php - example db usage: CMS Wordpress - Wordpress stores crated posts, usernames, passwords in a db that is onyl accessible to localhost ## Footprinting MySQL ```bash sudo nmap <ip_addr> -sV -sC -p3306 --script mysql* #run all sql related NSE scripts ``` ## Interact with MySQL Server ```bash mysql -u root -h <ip_addr> mysql -u root -p<password> -h <ip_addr> #NO SPACE between -p and password mysql -u root -p<password> -h <ip_addr> --skip-ssl #use extra flag if cert error appears mysql> show databases; #show dbs mysql> use <db_name>; #select db mysql> show tables; #show tables within selected db mysql> describe <table_name>; #show info for specified table mysql> show columns <table_name> #show columns for specified table mysql> select host, unique_users from <table_name>; #select specified columns from host_summary table mysql> select column_name_1 from table_name where column_name_2 = "<string>"; #for example select email for specified user name ``` | MySQL Command | Description | | | ----------------------------------------------------- | -------------------------------------------- | --- | | mysql -u user_name -p password -h <ip_addr> | connect to MySQL server with specified creds | | | show databases; | show all dbs | | | user database_name; | select specified db | | | show tables; | show tables for selected db | | | describe table_name; | show info for specified table | | | show columns from table>; | show columns for specified table | | | select * from table_name; | shows everything from specified table | | | select * from table_name where column_name= "string"; | search for needed string in specified table | | ## MySQL Config ```bash sudo apt install mysql-server -y cat /etc/myswl/mysql.conf.d/mysqld.cnf | grep -v "#" | sed '/^\s*$/d' #shows default config without comments and blank lines ``` ### Dangerous Settings | Setting | Description | | ---------------- | ----------------------------------------------------------------------------------------------------------- | | user | sets which user the MySQL service runs as | | password | sets password fort he MySQL user | | admin_address | IP address on whihc to listent for TCP/IP connections on administrative network interfaces | | debug | variable indicating current debug setting | | sql_warnings | variable that controls whether single-row INSERT statements produce an information string is warning occurs | | secure_file_priv | variable used to limit the effect of data import and export operations |