01 basic database operations

database

First, what is the database

  1. Database: data management system - install a system for managing data - management is the essence of the object file
  2. Location to store the data: memory, hard disk
  3. What is the system: running on a hardware basis, other management software

Second, the composition of the database

  1. Library: store multiple tables - Folder
  2. Table: contains a plurality of records of the same structure - File
  3. Record: a data comprising a plurality of key-value pairs key - binary data
  4. Field: description information - information itself == key-value - binary data
stu
id  name    age     gender
1   Bob     18      男
2   Tom     17      女

Third, the classification database

  1. Relations with non-relational

    Relations: a link between database tables and table - mysql

    Non Relationship: No Table Concept - redis, mongodb (relationship between the non-relational)

  2. Memory and hard drive

    Hard disk: data can be stored permanently - mysql, mongodb

    Memory: the high efficiency of data access - redis, memcache

  3. sql and nosql

    sql: database operated by sql statement
    nosql: database operation is key-value form (value is one record)
    STU - { 'name': 'Bob', 'Age': 18 is}
    stus - [{ 'name': 'Bob' , 'Age': 18 is}, { 'name': 'Tom', 'Age': 18 is}]
    name - 'Jerry'

Fourth, uninstall

Note: premise, start a terminal, enter mysql, if not prompt is not an internal or external command, on behalf of the database has been installed

  1. Directly connected

    • Search: service, retrieve mysql service, if the service is turned on, stop the service and remove the service - Start administrator terminal: mysqld --remove

    • search for

      Service, retrieve mysql service, no (use the mysql command to start)

      Stop service, start the administrator terminal

      tasklist | findstr mysql
      taskkill /pid 进程pid /f

  2. Connection timed out

    Search: service, service to retrieve mysql, you can remove the service

  3. Remove environment variables
    • If you can not even enter, to stop the service
    • If you add a service, remove the service
    • Cancellation environment variable configuration

V. Installation

  1. Download free installation unpack MySql version (5.6 - no initial password)
  2. Configuration environment variable
  3. Install server mysqld - install
  4. Start mysql

Sixth, the database connection

  1. Visitors landing

>>: mysql # may not be able to sign in, sign-up and consequently also can not do

  1. Account password

>>: mysql -u user name (root) -p password

eg: mysql -u root -p ‘123’

  1. Connected to the specified server MySql

>>: mysql -h ip address -P port number -u user name -p password

eg: mysql -h 127.0.0.1 -P 3306 -u root -p ‘123’

  1. Exit Database

>>: quit

>>: exit

1568961926322

Seven users View

  1. View the current logged-on user

>>: select user();

1568962099337

  1. All users can see the information produced by the root authority

    >>: select * from mysql.user; # display in the form of two-dimensional table

    >>: select * from mysql.user \ G; # display as columns

    >>: select user, password, host from mysql.user # view the user name, password, ip

1568962751289

  1. The root login, delete tourists (after the operation to restart the mysql service)

    >>: delete from mysql.user where user=“”;

  2. The root login, change password (after the operation to restart mysql)

    >>:update mysql.user set password = password(“密码”) where host=‘localhost’;

  3. 没有登录修改密码

    >>:mysqladmin -u 用户名 -p 旧密码 -h 域名 password ‘新密码’

    mysqladmin -u root -p ‘123’ -h locahlost password ‘123456789’

  4. root登录下,创建用户

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

八、数据库的基本操作

  1. 查看已有的数据库

    >>: show databases;

1568962904645

  1. 选择某个数据库

    >>:use 数据库名
    eg: use db1;

1568962956803

  1. 查看当前所有的数据库

    >>: select database();

1568963068796

  1. 创建数据库

    >>: create database 数据库名称 [charset=‘字符编码’];

    eg: create database db1 # 编码格式默认

    eg create dataase db2 charset = ‘utf8’

  2. 查看创建数据库的详细内容

    >>: show create database 数据库名称

    eg: show create database db1

  3. 删除数据库

    >>:drop database 数据库

    eg: drop database db1

1568963352244

九、表的基本操作

  1. 选择某个数据库

>>: user 数据库名;

eg user db;

  1. 查看已有的表

前提:先选取要操作的数据库

>>:show tables;

  1. 创建表(简易版)

>>: create table 表明(字段1 类型,….. 字段n 类型 );

eg: create table student(name);

  1. 查看创建表sql

>>: show create table 表名;

eg: show create table student;

  1. View table structure to create a sql statement

>>: desc table name;

eg: desc student;

  1. Delete table

>>:drop table 表名;

eg: drop table student;

1568963947207

Ten, the basic operation for recording

  1. View a list of all records in a data (if in the corresponding database, you can direct look-up table, simple version)

    >>: select * from table name; # Lite

    eg: select name, id from student; # simple query

  2. Inserting a plurality of fields to the table

    >>: insert into table (field) values ​​(= 1 field name field value, n = ... .. field name value, ... .;

    eg: insert into student values ​​(name = 'zhangsan', age = 29); # insert a data

    eg: insert into student values ​​(name = 'tom', age = 18), ( 'bob', 34); # inserting a plurality of values

    eg: insert into db.student values ​​(name = 'lisi', age = 10) # table inserted below the value specified library

  3. Modify the contents specified by the condition

>>: update table set field name value = 1, 2 ... field name = value = value where field

eg: update student set name = ‘bob2’ , age=18 where name = ‘lisi’;

  1. Delete records according to the conditions

>>: delete from table where field name = value;

eg: delete from student where name=‘bob2’;

1568964587318

1568965051550

1568965006048

1568964958246

Guess you like

Origin www.cnblogs.com/randysun/p/11563430.html