First, the basic operation of the database
1) Log in to MySQL server: mysql-u root-p password
2) View database: Show databases
3) View table: Show Tales from DB;
4) View table structure: DESC table;
5) Creating Table: Create table table ();
6) View Table data: SELECT * from table;
7) Insert data: INSERT into table (F1,F2) VALUES (' v1 ', ' v2 ');
8) Delete data: Delete from table where id=8;
9) Modify table data: Update table T1 set f1= ' 123 ', f2= ' abc ' where id=8;
10) Delete tables: drop table T1;
11) Delete databases: drop database D1;
Second, shell operation MySQL increase, delete, change, check
1) Connect to the database
#!/bin/bash
#mysql. Sh
MySQL='mysql-uroot-proot'
SQL="show Databases"
$mysql- e "$sql"
2) Shell operation MySQL Add, delete, change, check
#!/bin/bash
#mysql1. Sh
Conn="mysql-uroot-proot"
Case $ in
Select)
SQL="query statement "
;;
Delete)
SQL="DELETE statement "
;;
Insert)
SQL="INSERT statement "
;;
Update)
SQL="UPDATE statement "
;;
Esac
$conn- e "$sql"
Iii. Apache log segmentation and related scheduled tasks
#!/bin/bash
#logcut. Sh
Yesterday=' date-d yesterday +%y%m%d '
Srclog="/usr/local/apache2.4/logs/access_log"
Dstlog="/usr/local/apache2.4/logsbak/access_${yesterday}. Log"
MV $srclog $dstlog
Pkill -hup httpd//pkill -1 httpd re-read log file
CRONTAB-E//Mission plan
XX * * */mnt/logcut.sh
CRONTAB-L//View task schedule
Four, Apache log statistics of the MySQL database
Combine log splitting and log statistics into the database
#!/bin/bash
#logpv. Sh
Yesterday=' date-d yesterday +%y%m%d '
Srclog="/usr/local/apache2.4/logs/access_log"
Dstlog="/usr/local/apache2.4/logsbak/access_${yesterday}. Log"
MV $srclog $dstlog
Pkill -1 httpd
cat/usr/local/apache2.4/logsbak/access_20171125.log|awk '{print $}'| Sort|uniq -C |awk '{print $ ': "$ $}' > a.txt//The directory and filename here can be $dstlog
MySQL="mysql-uroot-proot"
For i in ' cat a.txt '
Do
PV='echo $i |awk-f: '{print '}'
IP='echo $i |awk-f: '{print $}'
SQL="insert INTO Text.countab (date,ip,num) value ('$yesterday', '$ip', '$PV ')"
$mysql- e "$sql"
Done
RM -rf a.txt
SQL="select * from Text.countab ORDER by ID"
$mysql- e "$sql"
CRONTAB-E//Mission plan
XX * * */mnt/logcut.sh
CRONTAB-L//View task schedule
Shell Script Programming Learning notes (iv) Shell operations database