MySQL user, library, table operations

User and privileged operations:  

Admin Login:-uroot-MySQL - the p- 
users to set passwords: the SET password = password (password); 
check the database for all users: the SELECT * from the mysql.user; 
view the user permissions: Show Grants for username @ Network Address [identified by password] 

ordinary user login: MySQL -u user name -h network address - the p- 
view the current user: select user (); 
view the current database: select database (); 
current time: now () 
to see if the current database is strict mode: select @@ sql_mode; 


create a user: create user username @ network address identified by password; 
user authorization:. grant all [SELECT INSERT UPDATE DELETE] on the database name table name to the username @ Internet address ( % means all) identified by the user's password; 
cancel authorization:. revoke all [SELECT INSERT UPDATE DELETE] on the database name table name from username @ network address [identified by password];
Modify user password: the SET password forUsername = password (password); 
view current user privileges: show grants;
mysql user management infrastructure operations

Library operations:  

View database: 
    Show Databases; 

view the current database: 
    the SELECT Database (); 

create the database: 
    the Create Database database name [charset UTF -8 ]; 

select the database: 
    the User database name; 

delete the database: 
    drop Database database name; 

modify the database: 
    the ALTER Database Database name charset utf8;
mysql database operations

Table operations:  

MySQL data types supported by 
  reference blog: https://www.cnblogs.com/Eva-J/articles/9683316.html
  reference blog: https://www.cnblogs.com/clschao/articles/9959559.html 
A numerical type (with constraints unsigned unsigned): 
        int: Integer 4 bytes   -2 ^ 31-2147483647 unsigned: 2 ^ 32-1 
        a float: single precision floating 4-byte 
        double: double precision floating point 8 byte 
        decimal: decimal value
     2 character types:. 
        char: fixed-length character, the number of characters that can be represented is limited (0 -255 ), reading and writing speed 
        varchar: variable-length character, the number of characters that can be represented multiple (0 -65535 ), read and write slow
    3 . time and date type :( system built-in function now () to get the current time) 
        year: Year 
        date: date 
        time: when minutes and seconds 
        datetime: year, month, day, hour 
        timestamp: year, month, day, hour ( 1970- between 2038, if not set it defaults to the current time)
     4  .enum and set type:
        enum (): enumeration, radio, automatic shield key does not exist
        set (): set, multiple choice, automatically block does not exist and deduplication
mysql data types supported
Constraints in MySQL 
  Reference blog: https://www.cnblogs.com/Eva-J/articles/9687915.html
  reference blog: https://www.cnblogs.com/clschao/articles/9968396.html
In MySQL constraints (may be used in conjunction with):
     1 integer unsigned:. The unsigned
     2 unique:. Unique only constraint can not duplicate the data type, but can not bind null
     3. non-empty:          Not null
     . 4 . The default value of the default value
     5 increment:. auto_increment must be numeric type, and provided a unique uNIQUE
     . 6 primary key:. primary key
     . 7 foreign key:. foreign key 
without setting the primary key is encountered constraint nonempty unique system default primary key!
MySQL in the integrity constraints
MySQL tables in operation 
  to create the table:     
# Syntax: 
Create Table table name ( 
field name 1 Type [(width) constraints], 
field name 2 types of [(width) constraints], 
Field Name Type 3 [(width) constraints] 
); 

# Note: 
1 . in the same table, the field names are not the same
 2 width and the constraints optional
 3. field names and types is required
Table creation statement
create table t1 (id int, name char ...); 
 Example: 
     # Create Table class ( 
     #      CID int Primary Key AUTO_INCREMENT, 
     #      Caption char (. 4) UNIQUE Not null # is not set non-empty, and only if ordered by primary key 
     # ) ;
Table create an instance

  View the table and the table structure:  

See the database table: show tables; 
Display Structure: 
             DESCRIBE T1; # see table structure can be abbreviated as: desc table name 
            Show Create Table T1 \ G; # Display detailed structure, can be added \ G 
            desc name;
View database tables and table structure

 

    


    
  
  

  

  

Guess you like

Origin www.cnblogs.com/open-yang/p/11411796.html
Recommended