Cyber Security Day21 - Database Knowledge

1. What is a database

  • A database is a warehouse for storing data, and this warehouse is more special

2. Why do you need a database (categorization is not clear)

  • store static data
    • On the storage server: pictures, videos, compressed packages
    • On the web server: html,js,css,php,python,java
    • In the database: text: articles, orders, commodities
  • interact with dynamic data
    • For e-commerce websites, these functions must interact with the database. Registered member, logged in member, purchase order, payment, logistics tracking, evaluation
  • Database administrator: DBA, high salary

3. Types of databases

3.1 Relational database

  • Essence: two-dimensional data table
  • Representative products: MySQL, oracle, sql server
    • oracle: At present, there are only stocks and no increments, and most of them will be replaced in the next three years in China
    • MySQL: the most popular Internet scene
    • sql server: Microsoft product
  • Access: access using sql language
  • Scenario: dynamic website backend
  • Advantages: data security is fully guaranteed
  • Disadvantages: low access efficiency, difficult expansion

3.2 NOSQL database

  • Positioning: a supplement to relational databases, not a substitute
  • Features: Not particularly related to data security, the core is high concurrency and large traffic
  • Products: memcach (memory database), redis (memory database), mongodb (document database)

3.3 new sql (domestic database) distributed database

  • Type: tidb, ob, Gaussian db, Dameng
  • Positioning: Domestic, large concurrency, large traffic, large data volume
  • Architecture: Distributed Database

3.4 Cloud database

  • Alibaba Cloud RDS, Tencent Cloud TDSQL

4. mysql relational database

  1. features
    1. Relational Database
    2. Use sql statement management
    3. Commonly used by Internet companies (free, open source, stable, active community, large concurrent solutions, data security)
  2. mysql is almost equal to mariadb so learn the latter

5. Install mariadb

  1. Install mariadb:yum install mariadb-server mariadb -y
  2. Startup and autostart
    方法一[root@oldboy ~] systemctl start mariadb  # 启动数据库
    方法二[root@oldboy ~] systemctl enable mariadb # 开机自启动
    
  3. Check: ss -lnt|grep 3306(if the result is red, it is right) orps -ef|grep mysqld
  4. Log in:mysql
  5. Database data directory and error log
    1. Order:rpm -ql mariadb-server
    2. Important directories in the results
      1. Database log:/var/lib/mysql
      2. Error log:/var/log/mariadb/mariadb.log
  6. Troubleshooting after installation
    1. View status:grep -i error /var/log/mariadb/mariadb.log
    2. The new data is installed normally and cannot be started. Try the method
      1. rpm -e --nodeps mariadb-server mariadb
      2. rm -fr /var/lib/mysql
      3. yum install mariadb-server mariadb -y

6. SQL Structured Query Language

  • SQL classification
    • DDL (Data Definition Language): Responsible for managing database basic data (except tables), keywords create, alter, drop, etc.
    • DCL (Data Control Language): operation and maintenance personnel need to master, keywords commit, rollback, etc.
    • DML (Data Manipulation Language): operate on the data in the database table, keywords insert, delete, update, etc.
    • DQL(Data Query Language): keyword select, etc.

7. Set password for mariadb

  1. Set a password for the administrator root:mysqladmin password oldboy123
  2. Log in after setting the root password:mysql -uroot -p
  3. Modify password: mysqladmin -uroot -p original password password new password

8. How to retrieve MySQL root password

  1. stop database process
    1. pkill mysqld(kill the mysql process, the process name is mysqld)
    2. ps -ef|grep mysql(Check to see if the mysql process has been stopped)
  2. Skip grant table (–skip-grant-table), skip network startup (–skip-network)
    1. /usr/bin/mysqld_safe --skip-grant-table --skip-network &
    2. ps -ef|grep mysql
  3. Login and change password
    [root@web01 ~] mysql
    MariaDB> UPDATE mysql.user SET password=PASSWORD("oldboy123") WHERE user='root' and host='localhost';
    MariaDB> flush privileges; ##刷新到磁盘生效
    MariaDB> quit
    
  4. restart mysql
    1. Kill the mysql service:pkill mysqld
    2. Check progress:ps -ef|grep mysql
    3. start up:systemctl start mariadb
    4. Check port:ss -lntup|grep 3306
  5. Login test:mysql -uroot -poldboy123

Guess you like

Origin blog.csdn.net/m0_73293867/article/details/131927377