Table and library operations MySQL database

mysql password cracking under the mac system
mysqladmin -uroot -p password "123" # accounts set the root password
mysqladmin -uroot -p123 password "123abc" # Changing the root password

forgotten how to force a refresh password after password?
1, the first stop mysql server
2, the terminal user enters a command to the super forms: the mysqld_safe --skip - Grant - Tables
. 3, a terminal in the open, enter: mysql -uroot -p landing MySQL
. 4, after entering mysql, change the root password; an input command: Update the mysql.user SET password = password ( "123") WHERE User = "the root" and Host = "localhost";
. 5, and then the refresh command inputs: the flush privileges;
. 6, then the terminal amassing mysql service kill
7, and then restart the normal mysql server.

Rights management
1, create an account to
    create a local account (only landed on that machine mysql server-side)
        the Create the User 'xu' @ 'localhost' IDENTIFIED by '123abc'
    create a remote account
        create user 'xu'@'192.169.0.30'
        create user 'xu'@'192.169.0.%' identifide by ' 123abc' # able to land on the 192.169.0 network of machines
        # using this account login
        mysql -uxu -p123abc -h server ip address
2, authorization
    . user: * * All permissions (does not include grant permission)
        to grant permission: grant All ON * * to 'xu' @ 'localhost';.
                grant the SELECT ON * * to 'xu' @ 'localhost'; released only queries. permission
        to remove permissions: revoke select on * * to ' xu' @ 'localhost'; delete permissions.
    db: * db1, library-level permissions (permission only for one library).
        granted permission db: grant select on db1. * to 'xu' @ 'localhost '; only the release of all tables in the database query db1 rights
    table_priv: db1.t1, table-level privileges
        granted permission: grant select on db1.t1 to 'xu ' @ 'localhost'; only t1 released under the table db1 database query permissions
    columns_priv: field level
        Grant permission: grant select (id, name, age) on db1.t1 to 'xu' @ 'localhost'; only under db1 table t1 release of id, name, age field of the query authority



additions and deletions to change search the library
by: Creating database
syntax: create database database name charset utf-8;

delete: delete the database
syntax: drop database database name;

change: change the character encoding of the database
syntax: alter database database name of the charset gbk;

check:
statement: 1, show databases; inquiries have What database,
    2, Show the Create database database name; the structure of a database query,
    3, the SELECT database (); name of the database query is used

to switch to a directory database: use the database name

table operating
a storage engine - -> type table of
    different ways of storing different tables corresponding to the types.
    Expression of popular point: storage engine is how to store data, how to build and how to update the index data, query data and other implementation technologies.

    The default in MySQL storage engine is innodb
    There are other storage engines: MyISAM storage engine, NDB storage engine, Memory storage engine, Infobright storage engine, NTSE storage engine, BLACKHOLE
    

II, table CRUD
By: create table
statement structure:
Create Table table name (
field name 1 Type [(width) constraints],
field name 2 types of [(width) constraints],
Field Name Type 3 [(width) constraints]
);
PS : 1, in the same table, the field name is not the same as
    2, the width and the constraint condition may select
    3, field names and type must have a

check: Check table structure:
sentence structure: 1, desc table;
        2, Show Create table table name \ G; detailed structure # View the table

delete: delete table
drop table user;

to change: change the table structure of
the table name change table:
    the aLTER table the old table name rename the new table name;
increase the field:
    the aLTER table table name add field name data type [(width) constraints];
    alter table add table field name data type [(width) constraints] first; # insert a new field in the first
    alter table add table field name data type [(width ) constraints] After field name; # insert a new field in the back of a field
to modify storage engine:
    ALTER table name table engine = innodb;
delete fields:
    alter table table drop field name;
modified field types:
    new type alter table table modify the field name field [(width), constraints];
table to increase the master key already exists:
    alter table table add primary key (field names, ...) # can be a single master key can also be conscious complex formation
delete the primary key:
    the ALTER the table table name drop primary key

copy table structure:    
    1, the Create the table new table name select * from table to copy names where 1 = 2; # only copy table structure, not copy the data in the table, (key will not be copied: primary keys, foreign keys and indexes are not copied)
    2, Create new table like table on table # copy table structure, and replicated together with the key.

Third, the data type
detailed reference:
    http://www.runoob.com/mysql/mysql-data-types.html
    http://dev.mysql.com/doc/refman/5.7/en/data-type-overview. HTML
. 1, an integer
    tinyint: the size of a signed byte range (-128,127), the scope of unsigned (0,256)
    int: size 4 bytes signed (-2 ** 31,2 ** 31-1), unsigned range (0, 2 ** 32-1)
    bigint: Size 8-byte symbol (-2 ** 63,2 ** 63-1), the scope of unsigned (0,2 ** 64-1)
2, float
    float: in decimal longer then reduced accuracy
    double: the number of decimal places relatively long, reduced accuracy, but more than float high precision
    decimal: precise, excessive number of decimal places, the accuracy will be reduced.
3, String
     char ([manufactured by setting the maximum byte stored bytes]): Default is 4 bytes.
         Advantages: fast access
         drawbacks: wasted space
     VARCHAR ([byte of storage provided maximum byte]): the number of data bytes store the number of bytes
         advantages: accurate, space-saving
         drawbacks: slow access speed
     ps: 1 Why varchar slow access speed, because data is stored in a varchar, will first be used to store data with one or two bytes, so that when read, it will first read the size data, in Depending on the size of the read data, this will lead to slow reading speed
        2, if the memory sub-section is equal to the maximum number of sub-time section, char varchar space smaller than that occupied. Varchar as to separate the sub-section 1 or 2 to be used to store data.

        sql optimization: 1, create a table, to be fixed-length type on the front, back discharge becomes long.
              2, when the data stored in the sub-section size> 255; path can be stored in a database file or URL
. 4, enumeration
    corresponding to a selected plurality of selection
    Such as sex: sex enum ( "male", "female") not null default = "male"
    default is to set the default value for this field. If the data is not optional insert will insert the default value in the options.
5, a collection of
    several options to select multiple
    such as hobbies: hobby set ( "soccer", "basketball", "LOL")
6, time
    date format: YYYY-MM-DD
    datetime format: YYYY-MM-DD HH: MM : SS
    Time format: HH: MM: SS
    year format: YYYY

PS: common datetime

Guess you like

Origin www.cnblogs.com/zrxu/p/11834094.html
Recommended