当前位置:网站首页>MySQL advanced knowledge points

MySQL advanced knowledge points

2022-06-12 01:50:00 Dark horse gold medal programming

Transaction concept and function

View concept and operation

Index operation

security management

trigger

stored procedure

Database backup and restore

windows Next MySQL Other knowledge :

10、 Backup and recovery
    Backup database staffer
    
c:\mysql\bin\mysqldump -uroot -proot staffer>e:\staffer.sql
    
Recover database staffer, You need to create an empty library staffer
c:\mysql\bin\mysql -uroot -proot staffer<staffer.sql
If you don't want to create it manually later staffer, Sure
c:\mysql\bin\mysqldump -uroot -proot --databases staffer>e:\staffer.sql
mysql -uroot -proot >e:\staffer.sql
  But then the system cannot exist staffer library , And cannot import a database with another name , Of course, you can modify it manually staffer.sql file
11、 Import data from text to database
    1) Using tools c:\mysql\bin\mysqlimport
    The function of the tool is to remove the file name extension and import it into the table name , Such as
    staffer.txt,staffer Are imported into staffer In the table
    Common options and functions are as follows
-d or --delete  Delete all information in the data table before importing new data into the data table 

-f or --force  Whether or not you've made a mistake ,mysqlimport Will force continued insertion of data 

-i or --ignore mysqlimport Skip or ignore those that have the same unique 
 Keyword line ,  Data in the import file will be ignored .

-l or -lock-tables  Lock the table before data is inserted , This prevents ,
 When you update the database , User queries and updates are affected .

-r or -replace  This option is related to -i Options do the opposite ; This option will replace 
 Records with the same unique keyword in the table .

--fields-enclosed- by= char
 When specifying the record of data in a text file, it is enclosed by ,  In many cases 
 The data is enclosed in double quotation marks .  By default, data is not enclosed by characters .

--fields-terminated- by=char
 Specifies the separator between the values of individual data , In a period separated file ,
 The separator is a period . You can use this option to specify the separator between the data .
 The default separator is the skip (Tab)

--lines-terminated- by=str
 This option specifies the string to separate data between rows in a text file 
 Or characters .  By default mysqlimport With newline For line separator .
 You can choose to replace a single character with a string :
 A new line or a return .

mysqlimport The common options of the command are -v  Display version (version),-p  Prompt for password (password) etc. .

12: The structure of the display table :
mysql> DESCRIBE MYTABLE;
13: Add a record to the table
mysql> insert into MYTABLE values ("hyq","M");
14: Load data into database tables in text mode ( for example D:/mysql.txt)
mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;
15: Import .sql File command ( for example D:/mysql.sql)
mysql>use database;
mysql>source d:/mysql.sql;
16: Clear the table
mysql>delete from MYTABLE;
17: Update the data in the table
mysql>update MYTABLE set sex="f" where name='hyq';

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
   SET col_name1=expr1 [, col_name2=expr2 ...]
   [WHERE where_definition]
   [ORDER BY ...]
   [LIMIT rows]
or

UPDATE [LOW_PRIORITY] [IGNORE] tbl_name [, tbl_name ...]
   SET col_name1=expr1 [, col_name2=expr2 ...]
   [WHERE where_definition]

UPDATE
Update the columns of rows in the existing table with new values .SET Clause indicates which column to modify and the value they should give .
WHERE
      If clause is given , Specify which record line should be updated . otherwise , All record lines are updated . If ORDER BY Clause is specified , The record rows are updated in the specified order .
      If you specify keywords LOW_PRIORITY,UPDATE The execution of will be delayed , Until no other client is reading the table .
      If you specify keywords IGNORE, The update statement will not abort , Even if a duplicate key error occurs during the update process . The conflicting record rows will not be updated .
      If in an expression from tbl_name Access a column in ,UPDATE Use the current value of the column . for instance , The following statement sets age The column value is its current value plus 1 :
mysql> UPDATE persondata SET age=age+1;
UPDATE The assignment is calculated from left to right . for instance , The following statement will age Set the column to twice its size , And then add 1 :
mysql> UPDATE persondata SET age=age*2, age=age+1;
If you set the column to its current value ,MySQL Notice this , Don't update it .
     UPDATE Returns the number of record lines actually changed . stay MySQL 3.22 Or later ,C API function mysql_info()
      Returns the number of matched and updated record lines , And in UPDATE Number of warnings that occurred during .
      stay MySQL 3.23 in , You can use LIMIT # To ensure that only a given number of record lines are changed .
      If one ORDER BY Clause is used ( from MySQL 4.0.0 Start supporting ), The record lines are updated in the specified order . This is actually only together with LIMIT Together is useful .
      from MySQL 4.0.4 Start , You can also execute a that contains multiple tables UPDATE The operation of :
UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;
Be careful : Multiple tables UPDATE Not available ORDER BY or LIMIT.
原网站

版权声明
本文为[Dark horse gold medal programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120144153495.html