Section 1 Introduction to MySQL
MySQL is the most popular relational database management system. In terms of WEB application, MySQL is one of the best RDBMS(Relational Database Management System) application software.
We use a relational database management system (RDBMS) to store and manage large amounts of data.
The so-called relational database is a database based on relational model, which processes the data in the database with the help of mathematical concepts and methods such as set algebra.
RDBMS, namely relational database management system, features:
- The data appears in tabular form
- Name of each record
- Each column is the data field corresponding to the record name
- Many rows and columns form a form
- Several forms form a database
Before learning MySQL database, let's first understand some terms of RDBMS:
- Database: A database is a collection of associated tables.
- data sheet: A table is a matrix of data. A table in a database looks like a simple spreadsheet.
- Columns: A column (data element) contains the same type of data.
- Row: a row (= tuple, or record) is a set of related data, such as a piece of data subscribed by a user.
- Redundancy: store twice as much data. Redundancy reduces performance but improves data security.
- Primary key: the primary key is unique. A data table can contain only one primary key. You can use primary keys to query data.
- Foreign key: a foreign key is used to associate two tables.
- Composite key: composite key (composite key) takes multiple columns as an index key, which is generally used for composite index.
- Indexes: use indexes to quickly access specific information in database tables. An index is a structure that sorts the values of one or more columns in a database table. A catalog similar to a book.
- Referential integrity: Referential integrity requires that nonexistent entities cannot be referenced in a relationship. And entity integrity are the integrity constraints that the relational model must meet in order to ensure the consistency of data.
MySQL is a relational database management system. This so-called "relational" can be understood as the concept of "table". A relational database consists of one or more tables, as shown in the figure:
- Header: the name of each column;
- Column (col): a collection of data with the same data type;
- Row: each row is used to describe the specific information of a record;
- Value: the specific information of the row. Each value must be the same as the data type of the column;
- Key: the value of the key is unique in the current column.
MySQL is a relational database management system developed by MySQL AB company in Sweden. At present, it belongs to Oracle company. MySQL is an associated database management system. The associated database saves the data in different tables instead of putting all the data in a large warehouse, which increases the speed and flexibility.
- MySQL is open source.
- MySQL supports large databases. It can handle large databases with tens of millions of records.
- MySQL uses the standard SQL data language form.
- MySQL can run on multiple systems and supports C, C + +, Python, Java, Perl, PHP, Eiffel, Ruby and Tcl.
- MySQL has good support for PHP, which is the most popular Web development language at present.
- MySQL supports large databases and a data warehouse with 50 million records. The 64 bit system supports a maximum table file of 8TB.
- MySQL can be customized and adopts GPL protocol.
Section 2 MySQL installation
(base) [root@localhost local]# mkdir mysql (base) [root@localhost local]# ll Total consumption 0 drwxr-xr-x. 2 root root 6 6 June 22-13:06 bin drwxr-xr-x. 2 root root 6 6 June 22-13:06 etc drwxr-xr-x. 2 root root 6 6 June 22-13:06 games drwxr-xr-x. 2 root root 6 6 June 22-13:06 include drwxr-xr-x. 2 root root 6 6 June 22-13:06 lib drwxr-xr-x. 3 root root 17 11 January 19:00 lib64 drwxr-xr-x. 2 root root 6 6 June 22-13:06 libexec drwxr-xr-x. 2 root root 6 11 June 22-16:46 mysql drwxr-xr-x. 2 root root 6 6 June 22-13:06 sbin drwxr-xr-x. 5 root root 49 11 January 19:00 share drwxr-xr-x. 2 root root 6 6 June 22-13:06 src (base) [root@localhost local]# cd mysql/ (base) [root@localhost mysql]# ll Total consumption 779100 -rw-r--r--. 1 root root 797798400 11 June 22-16:46 mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar (base) [root@localhost mysql]# tar -xvf mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar mysql-community-client-8.0.27-1.el8.x86_64.rpm mysql-community-client-debuginfo-8.0.27-1.el8.x86_64.rpm mysql-community-client-plugins-8.0.27-1.el8.x86_64.rpm mysql-community-client-plugins-debuginfo-8.0.27-1.el8.x86_64.rpm mysql-community-common-8.0.27-1.el8.x86_64.rpm mysql-community-debuginfo-8.0.27-1.el8.x86_64.rpm mysql-community-debugsource-8.0.27-1.el8.x86_64.rpm mysql-community-devel-8.0.27-1.el8.x86_64.rpm mysql-community-libs-8.0.27-1.el8.x86_64.rpm mysql-community-libs-debuginfo-8.0.27-1.el8.x86_64.rpm mysql-community-server-8.0.27-1.el8.x86_64.rpm mysql-community-server-debug-8.0.27-1.el8.x86_64.rpm mysql-community-server-debug-debuginfo-8.0.27-1.el8.x86_64.rpm mysql-community-server-debuginfo-8.0.27-1.el8.x86_64.rpm mysql-community-test-8.0.27-1.el8.x86_64.rpm mysql-community-test-debuginfo-8.0.27-1.el8.x86_64.rpm (base) [root@localhost mysql]# rpm -ivh mysql-community-libs-8.0.27-1.el8.x86_64.rpm --nodeps --force Warning: mysql-community-libs-8.0.27-1.el8.x86_64.rpm: head V3 DSA/SHA256 Signature, secret key ID 5072e1f5: NOKEY Verifying... ################################# [100%] In preparation... ################################# [100%] Upgrading/install... 1:mysql-community-libs-8.0.27-1.el8################################# [100%] (base) [root@localhost mysql]# rpm -ivh mysql-community-common-8.0.27-1.el8.x86_64.rpm --nodeps --force Warning: mysql-community-common-8.0.27-1.el8.x86_64.rpm: head V3 DSA/SHA256 Signature, secret key ID 5072e1f5: NOKEY Verifying... ################################# [100%] In preparation... ################################# [100%] Upgrading/install... 1:mysql-community-common-8.0.27-1.e################################# [100%] (base) [root@localhost mysql]# rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm --nodeps --force Warning: mysql-community-client-8.0.27-1.el8.x86_64.rpm: head V3 DSA/SHA256 Signature, secret key ID 5072e1f5: NOKEY Verifying... ################################# [100%] In preparation... ################################# [100%] Upgrading/install... 1:mysql-community-client-8.0.27-1.e################################# [100%] (base) [root@localhost mysql]# rpm -ivh mysql-community-server-8.0.27-1.el8.x86_64.rpm --nodeps --force Warning: mysql-community-server-8.0.27-1.el8.x86_64.rpm: head V3 DSA/SHA256 Signature, secret key ID 5072e1f5: NOKEY Verifying... ################################# [100%] In preparation... ################################# [100%] Upgrading/install... 1:mysql-community-server-8.0.27-1.e################################# [100%] [/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly. (base) [root@localhost mysql]# rpm -qa | grep mysql mysql-community-client-8.0.27-1.el8.x86_64 mysql-community-libs-8.0.27-1.el8.x86_64 mysql-community-server-8.0.27-1.el8.x86_64 mysql-community-common-8.0.27-1.el8.x86_64 (base) [root@localhost mysql]# mysqld --initialize (base) [root@localhost mysql]# chown mysql:mysql /var/lib/mysql -R (base) [root@localhost mysql]# systemctl start mysqld.service (base) [root@localhost mysql]# systemctl enable mysqld
cat /var/log/mysqld.log |grep password # view random password
Then enter mysql -uroot -p under the mysql folder, and then enter the random password to enter the database