MySQL - database operations

Create
Create database mydb1;
Create database mydb2 character set gbk;
Create database mydb3 character set gbk COLLATE gbk_chinese_ci;   
query
to view all databases in the current database server
Show databases;
view the definition information of the previously created mydb2 database
Show create database mydb2;
delete the previously created The mydb3 database
Drop database mydb3;
modify
the database in the view server, and modify the character set of mydb2 to utf8;
alter database mydb2 character set utf8;
delete Drop database mydb3;
* Others:
View the currently used database Select database(); switch DatabaseUse mydb2;

 

1. Backup
Mysqldump –uroot –p123 mydb1>d:/mydb1.sql
2.
Prerequisites for recovery: You must manually create a database
to restore outside the database: mysql –uroot –p123 mydb1<d:/mydb1.sql
restore in the database: you need to log in to the database
manually Create a database, use databaseName;
  source d:/mydb1.sql

 Note: Backup and first restore operations do not require a database login

 

Transaction Operation:

In cmd: The commit of mysql transaction is automatically committed by default.

View the submission method of MySQL transactions:

show variables like '%commit%';

Set the commit method of MySQL transaction:

set autocommit = off;

 When auto-commit is turned off, each subsequent statement must be manually committed to take effect.

 

Commit the transaction manually:

star transaction; start the transaction (after using this statement, the automatic transaction will be invalid)

commit; actually modify the database data.

rollback; restore data to its original state.

 

Transaction isolation level:

Dirty read: A transaction reads uncommitted data of another transaction.
Non-repeatable read: refers to inconsistent data read multiple times (reads the committed data of a transaction) Emphasize update [referring to changes in data content]
virtual read or Phantom reading: refers to the inconsistent data read multiple times, emphasizing insert [referring to the change in the amount of data]

 

1 Serializable: It can avoid the occurrence of dirty reads, non-repeatable reads, and virtual reads. (Serialization)
2 Repeatable read: It can avoid the occurrence of dirty read and non-repeatable read. (Repeatable read) Virtual read cannot be avoided
3 Read committed: Dirty read can be avoided (read has been committed)
4 Read uncommitted: The lowest level, none of the above conditions can be guaranteed. (Read uncommitted)
Mysql database default is Repeatable read
Oracle database default is read committed

Set the isolation level of the transaction:
Set session transaction isolation level read uncommitted;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326480959&siteId=291194637