MySQL database introduction, installation, database operation commands commonly used, basic sql statement,

1 MySQL introduced:

MySQL is a medium-sized, open source relational database management system (DBMS)

Relational database management system: a data organization and contact between the two-dimensional table consisting of; high maturity, similar to the variety of products sql syntax. Representative products: MySQL, Oracle

Non-relational databases: a flexible format (can be a key-value form, document form) fast, but low maturity, on behalf of products: Redis

User Action Data: User -> Applications -> Database Management System (the DBMS) -> OS -> Hardware

DBMS by a database management database storage engine

2.Ubuntu16.04 installation:

Install the server:

sudo apt-get install mysql-server

Install the client:

sudo apt-get install mysql-client

Installation Library:

sudo apt-get install libmysqlclient-dev

Ubuntu system to reset your password:

use mysql:

update user set authentication_string=password('123456') where user='root';

update user set plugin='mysql_native_password';

flush privileges;

3. Common operation command:

MySQL into the environment: mysql -h mysql host address -u user name -p;

Displays the database used: show databases;

Enter a database: use the database name;

View current database: select databases ();

Displays the current database of all the tables: show tables;

View table structure: desc table name;

Show all database storage engines: show engines;

4. Basic sql statement:

Creating data: create database database name [charset utf8];

Create a table: create table table name (

    Field name field data type constraints,

    ...

    )

create table student(
   id int primary key auto_increment,
   name varchar(20) not null,
   age int,
   sex char(5),
   score double not null     
);

Insert record: insert into the table name (field 1, field name 2 ,,,,) values ​​(value 1, value 2 ,,,,), (value 1, value 2, ...) ...

     Name insert into table values ​​(value 1, value 2 ,,,,), (value 1, value 2, ...); the list will insert values ​​in the order of the fields

Modify Record: update table set name field name = modified value of [, field name = modified value ,,,,] [where Condition];

Delete: 1> Record Delete: delete from table name [where Condition];

     2> delete tables: drop table table name;

     3> delete the database: drop datebase database name;

Search record: basic query: select field names from the table name [where conditions]

     Restrict the query: Query defined Article Number: select Name Field Name [where Condition] from the table limit up to the number of records;

          Defining a query from a specified offset Article Number: select field names from the name table [where Condition] offset limit, up to the number of bars;

     Sort query: select field names from the table name [where conditions] order by field name [desc] [, field name ...];

     Grouped query: select field names from the table name [where conditions] group by field name [having to grouped filter conditions];

          select type, avg (price) from product group by type having type = 'electronic'; // Query the average price of electronic products group

     Paging query: select field names from the table name [where conditions] limit (currentPage - 1) * pageSize, pageSize;

     Fuzzy query: select field names from table name where field names like matching condition;

          Wildcard: 1> represents any more characters select * from student where name like 'Zhang%'; // query all the rows of sheets

              2> _ stands for any one character select * from student where name like '_ _ Dragon'; // Query the name of a total of three words, the second word dragon  

  

Guess you like

Origin www.cnblogs.com/yanhonghong/p/11616310.html