On the MySQL database

What is a database

definition

The database is stored in the data warehouse. It's a great storage space, you can store one million, 10 million, hundreds of millions of pieces of data. But the database is not free to the data storage, there is a certain rule, otherwise the efficiency of the query will be low. In today's world is a world full of Internet data, filled with a lot of data. That is the world of the Internet is the World. There are many sources of data, such as travel records, consumer records, browse the web, messaging, and so on. In addition to text type of data, images, music, sound are data. Data is typically stored in memory, hard disk.

Development Status

In the history of the database, the database has gone through various stages of development of hierarchical databases, network and relational databases such as rapid development of database technology in various aspects. In particular relational database product database has become the most important one, since the 1980s, almost all of the new database vendor's database products support a relational database, even if some non-relational database products support almost all relational databases Interface. This is mainly traditional relational databases can better solve the problem of managing and storing relational data. With the advent of cloud computing and big data era of development, relational databases are increasingly unable to meet the needs, mainly due to an increasing number of semi-relational and non-relational data storage management needs to use the database in order at the same time the emergence of new technologies, distributed database technology and other technologies also put forward new demands, so more and more non-relational databases began to appear, such databases and traditional relational database design and data structures have very different, they are more emphasis on high concurrent read and write and store large data database data, such databases are generally referred to as NoSQL (Not only SQL) database. The traditional relational database in some traditional areas continued to maintain a strong vitality.

The basic idea of ​​the database

Library: build a multi-table database (storing multiple tables), it is essentially a folder

Table: constructing a plurality of data tables (comprising a plurality of records of the same structure), essentially file

Record: a storing of data (data comprises a plurality of key-key-value pairs), the file is essentially a record of data (binary data)

Database Category

relational database

Relational database storage format can directly reflect the relationship between the entities. Relational databases and common form is quite similar to relational database tables between the table and there is a lot of complex relationships. Common relational databases have Mysql, SqlServer and so on. In the lightweight or small applications, using a different relational database has little effect on system performance, but when building large applications, you need to business needs and performance requirements of the application in accordance with, select the appropriate relational database.

Relational database more suitable for processing structured data, such as student grades, address, etc., such data generally requires the use of a structured query, e.g. join, in such a case, the performance ratio of a relational database will NoSQL databases more preferred, and greater accuracy. Due to the size of structured data is not too large, the size of data growth usually predictable, so better to use a relational database for structured data. Relational databases great attention to the operation of transactional data consistency, if this area is undoubtedly requires a relational database can satisfy.

Summary: The concept of a relational database table, a record is stored in the data table, the structure of the data processing is more appropriate.

Non-relational databases (NoSQL)

With the recent expansion of the technical direction, a large number of databases such as NoSql MongoDB, Redis, Memcache database structure for simplicity, to avoid redundancy, the connection table affect performance, abandon complex distributed object is designed.

Refers to a distributed, non-relational, not ensure compliance data storage systems ACID principles. CAP NoSQL database technology and theory, consistent hashing algorithm is closely related. The so-called CAP theory, is simply a distributed system can not meet the availability, consistency and fault-tolerance partitions these three requirements, one-time meet two requirements is the upper limit of the system. The consistent hash algorithm refers to a NoSQL database in the application process, a data algorithms to meet the work requirements arising under normal circumstances, the algorithm can effectively solve the problems of work but there are also drawbacks, namely work complete quality will change with the node fluctuate, when too many nodes, the relevant results of the work can not be so accurate. This issue, the working efficiency of the entire system is affected, resulting in garbled data and the error rate of the entire database system greatly improved, there may even be content to migrate data node, the error code information. Nevertheless, NoSQL database technology still has a very distinct application advantages, such as database structure is relatively simple, good read and write performance under a large amount of data; store at any time to meet the needs of custom data format, ideal for large data-processing work.

NoSQL database for the pursuit of speed and scalability, changing business scenarios. [5] For a more appropriate processing unstructured data, such as articles, reviews, data such as full-text search, machine learning, usually used only for blurring, do not need as structured data as accurate inquiry, but such data the data is often massive scale, the scale of data growth is also often impossible expectations, and scalability of NoSQL database is almost unlimited, so NoSQL database can satisfy this type of data storage. NoSQL database using a large number of key-value can get a lot of unstructured data, data and high extraction efficiency, but it with structured data query effect is relatively poor.

NoSQL databases are still not a unified standard, it now has four broad categories:

(1) to store key-value pair (key-value): represents the software Redis, its advantages can quickly query data, but the disadvantage is the relationship between the need to store data. [3]

(2) Column storage: On behalf of the software Hbase, it has the advantage of fast data query, data storage scalability strong. The disadvantage is the function of the database has limitations. [3]

(3) document database storage: On behalf of the software MongoDB, it has the advantage of the data structure requirements are not particularly stringent. The disadvantage is the poor performance of queries, as well as the lack of a unified query language. [3]

(4) pattern database stores: represent software InfoGrid, its advantages can be easily calculated using the structure of FIG correlation algorithm. The disadvantage is that in order to get the results must be evaluated throughout the map, and the face is not suitable data model, graphical database difficult to use.

Summary: non-relational database with no tables concept, based on key-value store data in key-value pairs

Start with a database connection

Start the server

bin address after installation in the first configuration to the folder path environment variable

1569144518544

First search: service, service to retrieve mysql

1569144721330

If you have to stop the service and remove the service (Start administrator terminal input mysqld --remove)
1569144866373

If no, then enter mysqld install the administrator terminal, then enter the mysqld start

Connect to the database

  1. Guest Sign

    >:mysql
  2. Account password

    >:mysql -uroot -p
        #回车后输入密码,如果没有密码就直接回车,也可先将密码写在-p后再回车(没设密码就直接回车)
  3. Connected to the specified server MySQL

    >:mysql -h ip地址 -p端口号 -u账号 -p密码
        #举例:
        >: mysql -hlocalhost -P3306 -uroot -p
  4. Exit Database

    >:quit
    >:exit

View user information

  1. View the current user

    >: select user();
  2. Without login, change password

    >: select * from mysql.user;
    >: select * from mysql.user \G
    >: select user,password,host from mysql.user;
  3. With root privileges can view all user information

    >: delete from mysql.user where user='';
  4. The root login, delete tourists (after the operation to restart the MySQL service)

    >: update mysql.user set password=password('12345678') where host='localhost';
  5. The root login, change password (after the operation to restart the MySQL service)

    >: mysqladmin -u用户名 -p旧密码 -h域名 password "新密码"
    例>: mysqladmin -uroot -p12345678 -hlocalhost password "root"
  6. root login, the user is created

    >:grant 权限们 on 数据库名.表名 to 用户名@主机名 identified by '密码';

The basic operation of the database

  1. View existing database

    >:show databases;
  2. Select a database

    >:use 数据库名
  3. View current database

    >:select database();
  4. Create a database

    >:create database 数据库名 [charset=编码格式];
  5. View details of the database

    >:show create database 数据库名;
  6. Delete Database

    >: drop database 数据库名;

Basic operation table

Premise: First select the database to be operated

  1. View existing table

    >:show tables;
  2. Create a table

    >:create table 表名(字段们);
  3. View table creation sql

    >:show create table 表名;
  4. View to create a table structure

    >:desc 表名;
  5. Delete table

    >: drop table 表名;

Basic operation records

  1. View all records of a table in a database (if in the corresponding database, you can directly see table)

    >: select * from [数据库名.]表名;
  2. All fields of the table to insert data

    >: insert [into] [数据库名.]表名 values (值1,...,值n);
  3. Modify the contents specified by the condition

    >: update [数据库名.]表名 set 字段1=新值1, 字段n=新值n where 字段=旧值;
  4. Delete records according to the conditions

    >: delete from [数据库名.]表名 where 条件;

Guess you like

Origin www.cnblogs.com/MrYang161/p/11568773.html