MySql Reviews

RDBMS

  • The primary key (primary key):
    • A table can have one primary key
    • It can not be null
    • A combination of one or more columns
    • You can uniquely identify each row
    • Composite component can not contain extra columns (after deleting this column, the remaining columns are still not unique)
    • Innodb the table if there is no primary key, it will automatically define a hidden primary key
  • Foreign key:
    • Put A表in 字段and B表the 主键association (at A表the time of insertion will check 外键in B表whether 存在)
    • Association:
      • restrict (limit): If the recording association table B Table A, Table B modified to delete the primary key will fail.
      • cascade (cascade): A modified automatically deletes the corresponding record in the table B modified to delete the primary key table.
      • no action (do nothing)
      • set null: A foreign key will automatically record corresponding table are set to NULL (provided that the foreign key can not be set to not null) B delete edit table's primary key.

use

  • log in:
mysql -h localhost(本地可省略) -u root -p
Enter password:********
  • Create a user:
    • Log in as root
    • Increase recorded in the table mysql.user
create user username identified by 'password';
  • Modify permissions:
    • Create rights record in the table mysql.db
grant all privileges on dbname.* to username@'%' identified by 'password';
flush privileges;
  • View permissions:
show grants for 'username';

grammar

  • Create a database:
create database 数据库名字;
  • Delete the database:
drop database 数据库名字;
  • Select Database
use 数据库名字;
  • Create a data table:
create table 表名(名字 类型);
  • Delete the data sheet:
drop table 表名;
  • Insert data
insert into 表名(字段)values();
  • update data:
update 表名 set 字段1=1, 字段2=2;
  • delete data
delete from 表名 where子句;
  • Auto-increment primary keys:
    • May be provided 自增步长to facilitate horizontal partition table (e.g.: step 100, can be divided up table 100).
    • View 自增步长:show variables like ‘%auto_inc%’;
    • Modify 自增步长:set auto_increment_increment=100 ;
    • View 全局自增步长:show global variables like ‘%auto_inc%’;
    • Modify 全局自增步长:set global auto_increment_increment=100 ;
    • Persistence Review:set persist auto_increment_increment=100 ;(Local and global variables will be changed, restart the MySql modify the value will not be lost).
    • Note: Before MySql8 innodb表will 重启later 丢失自增idlead to bug values, there is no problem after MySql8.
    • Note 2: The need to re-link the database to be valid after modify variables.
  • Vertical table: field can be split into a large table of multiple tables, in which one of the automatically generated id, id other tables corresponding to the first table id can be used, so that the well can be multiple tables Information Woke up.
Published 41 original articles · won praise 4 · Views 3882

Guess you like

Origin blog.csdn.net/weixin_42487874/article/details/103640102