MySQL basics--(1) [Database overview, install MySql]

table of Contents


1. Database overview


1.1 Why study databases


In the previous Java learning, the first thing to learn is to store data in an array; then to the object-oriented part, store the data in an object; then learn the collection, and then store the data in the collection; these will The data is stored in the memory; once the computer is suddenly powered off and other situations occur; data may be lost if it is not saved in time; then when you learn the IO stream, you can serialize/deserialize the data to circulate the data between the memory and the hard disk file ; But in this case, the data may have efficiency problems when querying.

Therefore, the emergence of the database has also solved some problems.The data in the database is stored in the hard disk file in a specific way.

  • Using a database, data can bePersistenceSave it locally.
  • It is very convenient in data management. It can be managed by using the management system.Structured query.

1.2 About the database


Database (DataBase) is "a warehouse that organizes, stores, and manages data according to a data structure." It is a collection of organized, shareable, and unified management of large amounts of data stored in the computer for a long time.
Database is a warehouse for storing data. It has a large storage space, which can store millions, tens of millions, or hundreds of millions of data. But the database does not store data arbitrarily, there are certain rules, otherwise the query efficiency will be very low. Today's world is an Internet world full of data, full of large amounts of data. That is, the Internet world is the data world. There are many sources of data, such as travel records, consumption records, web pages browsed, messages sent, and so on. In addition to text-type data, images, music, and sound are all data.
Database is a computer software system that stores and manages data according to data structure. The concept of a database actually includes two meanings:
(1) A database is an entity, which is a "warehouse" that can store data reasonably, and users store transaction data to be managed in the "warehouse". There are "data" and "library". These concepts are combined into a database.
(2) Database is a new method and technology of data management, which can organize data more appropriately, maintain data more conveniently, control data more closely, and use data more effectively.

DB: Database (DataBase) 仓库
[a container for storing data, it holds a series of organized data]

DBMS: Database Management System (DataBase Management System) 管理系统
[also known as database software or database products, used to create or manage DB]

SQL: Structured Query Language (Structure Query Language) 管理系统与仓库之间的桥梁
[The language used to communicate with the database is not unique to a certain database software, but a common language for almost all mainstream database software]


The relationship between these three, DBMS to communicate DB (database) through SQL language


1.2 (1) Classification of databases


Divided by the storage type of the data:


Relational Database


A relational database (Relational database) refers to a database that uses a relational model to organize data. It stores data in the form of rows and columns to facilitate users’ understanding. The series of rows and columns in a relational database are called tables. A set of tables make up the database. The user retrieves the data in the database by query, and the query is an execution code used to limit certain areas in the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and the relationships between them.

Oracle: powerful, chargeable.
MySQL is fast, reliable, open source, free
SQL Server (Microsoft): can only be installed on the Windows operating system
DB2 (IBM): suitable for processing massive amounts of data, chargeable.


Non-relational database


NoSQL, generally refers to non-relational databases. With the rise of Internet web2.0 websites, traditional relational databases have been unable to handle web2.0 websites, especially the super-large-scale and high-concurrency SNS-type web2.0 pure dynamic websites, and there have been many insurmountable problems. The non-relational database has been developed very rapidly due to its own characteristics. NoSQL database was created to solve the challenges brought by multiple data types in large-scale data collections, especially big data application problems.

MongoDb document database (based on the key-value pair storage database, nesting key-values ​​between them is allowed)

Redis key-value pair storage database


1.2(2) MySQL database


MySQL is a relational database management system developed by the Swedish company MySQL AB and is a product of Oracle. MySQL is one of the most popular relational database management systems. In terms of web applications, MySQL is one of the best RDBMS (Relational Database Management System) application software.
MySQL is a relational database management system. Relational databases store data in different tables instead of putting all data in a large warehouse, which increases speed and flexibility.
The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software adopts a dual authorization policy, divided into community version and commercial version. Due to its small size, fast speed, low total cost of ownership, especially the characteristics of open source, generally small and medium-sized website development chooses MySQL as the website database.


Install MySQL


Download on MySql official website

After installation, after some steps such as initializing the database are completed; use the command on the command line

net start mysql

Start Mysql;

Insert picture description here

Available commands:

ALTER USER  'root'@'localhost'  IDENTIFIED WITH mysql_native_password BY  '这里填入想要设置的密码';

set password;


Use the command line to connect to mysql
login: mysql [-hlocalhost -P3306] (this machine can be omitted) -uroot -p (you can write the password directly without spaces)
-h: host name
-P: port number
-u: user name
-p: Password
Exit: exit

View the version of the mysql database
select version(); (mysql command)
•Common commands
for MySQL View all current databases: show databases;
select the specified library: use library name
View all current tables: show tables;
view all other libraries Table: show tables from library name;

Simple command line usage.

Insert picture description here

When not using the database; you can use the command

net stop mysql

Close MySql.


After the MySQL installation is complete, you can find and install the visual client tool;

For example: SQLyog / Navicat