Database Grooming (rights management, backup, storage, triggers, transactions, views)

authority management:

  use mysql

  Add users, the users of these ip specified user name and password to access through

  create user 'username' @ "ip" identified 'password' where, ip can use to specify the number of fuzzy address

  Delete User drop user 'username' @ "ip" 

  Authorization grant select, insert, uqdate on library name table name to 'username' @ "ip".;

  Puncturing the right to revoke all on the library name table name from 'username' @ "ip";

  After modifying permissions, we need to flush privileges; to refresh

  Modify User rename user 'username' @ 'ip address' to 'new user name' @ 'new ip address'

  Change password set password for 'username' @ 'ip address' = ( 'new password');

database backup:

  Backup Database: mysqudump -h ip ... -p 3306 -u ... -p ... library name> is the file path at this time to get all the statements to create the database, known as logical backup

  Restore the database: create a library of the same name to be restored, then mysqudump -h ip ... -p 3306 -u ... -p ... library name <file path that can change the direction of the arrow

        Not created, then added before the backup repository name a '-B', when the recovery does not need to build, do not add the library name

  Points table, divided backup: shell circulating library name or table name

  Incremental backup: realized by bin-log log. Primary library operations, and an incremental backup copy to the database from a backup master; separate read and write, the write data is written to the primary database, the read data is only read from the library.

Data availability:

  After the primary database downtime, automatically open from the library, and receiving online content corresponding to the program

  While monitoring the operation of two libraries

Cluster:

  Done modulo data packet processing, the remainder is allocated according to different servers. This group becomes a cluster architecture.

view:

  trying to create view name as select * from course;

  Generating a virtual library of the same content data, the data can be combined with a plurality of tables, to avoid the need to repeat multiple operations.

  Modifying views joint may have a plurality of tables produced complex effects, and inefficient. Not recommended for use.

trigger:

  During certain operating sql statement so that it can automatically trigger some action.

  Creating triggers:

  It must first declare statement terminator, after the change back ''; ''

  delimiter // # Here is the change at the end, into a symbol of what can be

  create tigger cmd_tri after insert on cmd for each row//

  begin

  if new. field = 'no' then

  insert into table (field 1, field name 2) values ​​(. new field 1, field 2 new new.);

  end if;

  end//

  delimiter; # here is the terminator back to the original;

  It can trigger a series of operations by recording the error status, the error term saving time and error log form

  Delete triggers:

  drop tigger trigger name;

Transaction:

  Multiple sql statements bundled together to perform, conduct an atomic operation, all of the implementation can take effect, there is an error on all rolled back.

  Transaction Start;
  Update User SET Balance = 900 WHERE name = 'WSB'; pay to buy # 100 yuan
  update user set balance = 1010 where name = 'chao'; # mediation took 10 yuan
  uppdate user set balance = 1090 where name = ' ysb '; # seller was 90, did not get the abnormal operation
  rollback; # If the above three sql statement appeared abnormal, directly ROLLBACK, the data directly back to the original state.
       commit; # just not commit, the data is not saved on the hard disk. After performing commit no way a rollback.

Stored Procedures:

  In the process of writing high storage complex sql statement, on the service side, when developers use related functions can be called, efficiency

Create a stored procedure (no-argument):

  delimiter //
  create PROCEDURE p5()
  BEGIN
  sql语句;
  END //
  delimiter ;

  After execution, the use of call p1 (), once inside the sql statement will be executed.

  Delete stored procedure:

  drop produre stored procedure name;

Create a stored procedure (there are parameters):

  Three kinds of inputted parameters, output parameters have, both input and output parameters

  Input parameters:

  p2(

  in the parameter name 

  )

  

  

   

  

 

  

Guess you like

Origin www.cnblogs.com/shachengcc1/p/11447657.html