Easy to understand MySql is easy to operate and easy to use

Posted by kellydigital on Wed, 09 Feb 2022 07:09:27 +0100

The server:

  1. Hardware server (personal computer, server in computer room -- blade server)
  2. ECS: (Alibaba cloud, Tencent cloud, Huawei cloud, etc.)

Software server:

You open a service on your PC or (cloud server). (software server).

  1. ftp server: default port: 21
  2. http server: default port: 80 (Apache, Nginx)
  3. https server: default port: 443
  4. mysql server: default port: 3306

It should be noted that if the port is not occupied, there is no way to serve the client.

1.1 Mysql

mysql is a database. Is to store data. Then why not use txt files or xls documents. Because query insert... It's troublesome and slow. mysql is fast. mysql is an open source data. (no charge)

1.1.1 MySQL server installation

  • Download mysql * officially exe

  • Use integrated software. (mysql server, http server, ftp server...)

    Pagoda, phpStudy

    Just start it directly.

1.1.2 how to connect to mysql server

The database has one key point:

Account name and password are required. Multiple account names and passwords can be created, and each account is independent. However, except for the root account, root contains the permissions of all users.

  • Using cmd command

    mysql -u root -p enter and enter the password. mysql > if you see this form, it means that you have successfully entered the mysql server.

  • UI interface

    Navicat for MySQL

  • If mysql was previously installed

    Open the cmd window as an administrator and enter the following command:

    sc delete mysql

1.1.3 Mysql command

Database server: database (multiple), in the database (multiple tables), in the table (multiple data)

  • database

    //Show all databases

​ show databases;

/ / create database

create database database name;

/ / delete the database

drop database database name;

/ / select database (switch database)

use the name of the database;

  • data type

    int(TINYINT),char,date

  • Table (an abstraction of data)

    To create a table, you must have a primary key. Generally, the primary key name is id value, and the id value increases automatically.

    show tables; // Show all tables

    desc table name; View all fields in the table.

    Design to create

    create table table name(

    Field name field constraints

    )

    create table student_(

    ​ id int(10) PRIMARY KEY AUTO_INCREMENT ,

    ​ student_id varchar(255),

    ​ student_name varchar(32),

    ​ student_age tinyint(3),

    ​ student_phone varchar(12)

    );

    • Delete table

      drop table name;

  • data

    Add, delete, modify and check.

    • Add data (insert data)

      insert into table name (field 1, field 2, field 3,...) values("", .....)

      insert into student_base_info(student_id, student_name, student_age, student_phone) values("2022004", "Xiao Gang", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("2022005", "Xiao Sun", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("2022006", "Xiao Zhao", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("2022007", "Jay", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("2022008", "Xingchi", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("2022009", "rushing", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("20220010", "RT Mart", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("20220011", "Xiao Zhou", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("20220012", "Fei Zhang", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("20220013", "Li Si", 20, "17303835241");
      insert into student_base_info(student_id, student_name, student_age, student_phone) values("20220014", "Li Gang", 20, "17303835241");
      
      
      
    • Update data

      update table name set field name = "new value";

      Only modify Xiao Ming's age:

      update table name set field name = "new value", field name = "where id=2;

    • Delete data

      delete from table name// If there are no conditions, all data will be deleted

      delete from table name where id = 2// If you delete this data, it will never be stored when adding new data.

    • Query data

      select * from table name;

      select student_id,student_name from table name;

      select * from table name where id=2// Conditional statement

      //Pagination

      If you are page 1, 10 data

      select * from student_base_info limit 0, 10; (0: offset value, 10: 10 pieces of data)

      If you are page 2, 10 data

      select * from student_base_info limit (page-1)*pageSize, pageSize

Topics: Database MySQL server