MySQL database _ basic introduction to the database

A brief introduction to the database

Storage of "data"

According to legend, in ancient times, people counted or recorded things large and small through the method of “tethering notes”, which is the only clue to help people recall the past.

When characters are produced, people use characters to record traditional information and data.

However, the traditional way of recording information and data has some shortcomings, such as Data is not easy to save, it is inconvenient to back up, information search is slightly difficult, etc...

After entering the modern era, people store information and data through "files" and "databases".

file

  • The use of files is simple, such as opening (open), reading and writing (read/write), and closing (close) of files in Python language
  • However, for some files with a large amount of data, the file format cannot be satisfied well, and there is still a problem of poor performance.
  • Not easy to expand

database

  • Persistent storage
  • Very high read and write speed
  • Ensure the validity of the data
  • Very good program support, easy to expand

Taking a mall as an example, the data programmers see looks like this:

=====Picture======

The user who visits the mall sees this:

=====Picture======

database

  • A database is a special file in which the required data is stored

=====Picture======

Core Elements of Relational Database

  • Data line (record)
  • Data column (field)
  • Data table (collection of data rows)
  • Database (collection of data tables)*

=====Picture======

RDBMS

  • The full name of RDBMS: RDBMS Relational Database Management System (relational through "tables")

  • Currently, two types of databases are mainly used: relational databases and non-relational databases. This section mainly discusses relational databases. For non-relational databases, we will learn later

  • The so-called relational database RDBMS is a database built on the basis of a relational model. It uses mathematical concepts and methods such as set algebra to process data in the database.

  • View database ranking: https://db-engines.com/en/ranking

  • The main products of relational database:

    • oracle: used in previous large-scale projects, banking, telecommunications and other projects
    • mysql: the most widely used relational database in the web era
    • ms sql server: used in Microsoft projects
    • sqlite: lightweight database, mainly used in mobile platforms

The relationship between RDBMS and database

Insert picture description here

SQL

What is SQL?

SQL全称:Structured Query Language

SQL is a structured query language, a database language used to operate RDBMS, current relational databases all support the use of SQL language to operate, that is to say you can operate all the relationships of oracle, sql server, mysql, sqlite and so on through SQL Database

  • SQL statements are mainly divided into:
    • DQL: Data query language, used to query data, such as select
    • DML: Data manipulation language, add, modify and delete data, such as insert, udpate, delete
    • TPL: Transaction processing language, to process transactions, including begin transaction, commit, rollback
    • DCL: Data control language, for authorization and permission recovery, such as grant and revoke
    • DDL: Data definition language, for database, table management, etc., such as create, drop
    • CCL: Pointer control language, complete table operations by controlling the pointer, such as declare cursor
    • For web programmers, the key point is data crud (addition, deletion, modification, and check). You must be proficient in writing DQL and DML, and be able to write DDL to complete database and table operations. **Other languages ​​such as TPL, DCL, CCL can be understood
    • SQL is a special language designed to operate relational databases
    • It can be case-sensitive, but it is not case-sensitive by default.

About SQL learning requirements

  • Familiar with the writing of SQL statements related to data addition, deletion, modification, and query
  • Manipulating data in Python code is to manipulate data through SQL statements
# 创建Connection连接
conn = connect(host='localhost', port=3306, user='root', password='mysql', database='python1', charset='utf8')
# 得Cursor对象
cs = conn.cursor()
# 更新
# sql = 'update students set name="刘邦" where id=6'
# 删除
# sql = 'delete from students where id=6'
# 执行select语句,并返回受影响的行数:查询一条学生数据
sql = 'select id,name from students where id = 7'
# sql = 'SELECT id,name FROM students WHERE id = 7'
count=cs.execute(sql)
# 打印受影响的行数
print(count)

A brief introduction to MySQL

  • Click to view the official MySQL website

  • MySQL is a relational database management system, developed by the Swedish company MySQL AB, and later acquired by Sun, which is later acquired by Oracle, and currently belongs to Oracle's products

Features

  • Written in C and C++, and tested with a variety of compilers to ensure the portability of the source code

  • Support multiple operating systems, such as Linux, Windows, AIX, FreeBSD, HP-UX, MacOS, NovellNetware, OpenBSD, OS/2 Wrap, Solaris, etc.

  • Provides APIs for multiple programming languages, such as C, C++, Python, Java, Perl, PHP, Eiffel, Ruby, etc.

  • Support multi-threading, make full use of CPU resources

  • Optimized SQL query algorithm, effectively improve query speed

  • Provide multi-language support, common encoding such as GB2312, BIG5, UTF8

  • Provide multiple database connection methods such as TCP/IP, ODBC and JDBC

  • Provide management tools for managing, checking, and optimizing database operations

  • Large database. Can handle large databases with tens of millions of records

  • Support multiple storage engines

  • MySQL software adopts a dual authorization policy, which is divided into a community version and a commercial version. Due to its small size, fast speed, low total cost of ownership, especially the feature of open source, the development of small and medium-sized websites generally chooses MySQL as the website database

  • MySQL uses standard SQL data language form

  • Mysql can be customized, using the GPL agreement, you can modify the source code to develop your own Mysql system

  • Online DDL change function

  • Copy global transaction ID

  • Copy crash-free slave

  • Copy multithreaded slave

Open source, free, no money, widely used, cross-platform support is good, and APIs that can be called in multiple languages ​​are provided.

Is the first choice for learning database development.

Guess you like

Origin blog.csdn.net/weixin_42250835/article/details/90211907