首页 > 代码库 > mysql 命令行操作1

mysql 命令行操作1

查看版本号 :SELECT @@version;或者status;

 

1.设置数据库系统的事务隔离级别
mysql> set global transaction isolation level read committed;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @@global.tx_isolation;
+-----------------------+
| @@global.tx_isolation |
+-----------------------+
| READ-COMMITTED        |
+-----------------------+
1 row in set (0.00 sec)

mysql> SELECT @@tx_isolation;
+-----------------+
| @@tx_isolation  |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.00 sec)
2.设置会话的事务隔离级别
mysql> set session transaction isolation level read committed;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @@global.tx_isolation;
+-----------------------+
| @@global.tx_isolation |
+-----------------------+
| READ-COMMITTED        |
+-----------------------+
1 row in set (0.00 sec)

mysql> SELECT @@tx_isolation;
+----------------+
| @@tx_isolation |
+----------------+
| READ-COMMITTED |
+----------------+
1 row in set (0.00 sec)
3.设置mysql不自动提交事务
mysql> set autocommit = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
|            0 |
+--------------+
1 row in set (0.01 sec)
4.使用start transaction;或begin;显示的开启一个事务
mysql>
mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> use test;
Database changed
mysql> insert into pwd values(441,55555);
Query OK, 1 row affected (0.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)
5.使用rollback回滚
mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like autocommit;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit    | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

mysql> use test;
Database changed
mysql> insert into pwd values (2,11111);
Query OK, 1 row affected (0.00 sec)

mysql> rollback;
Query OK, 0 rows affected (0.00 sec)
6.查看二进制日志
C:\Program Files\MySQL\MySQL Server 5.5>MySQLbinlog  data.000001
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#161109  8:56:53 server id 226  end_log_pos 107         Start: binlog v 4, server v 5.5.31-log created 161109  8:56:53 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG 
VXQiWA/iAAAAZwAAAGsAAAABAAQANS41LjMxLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAABVdCJYEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
/*!*/;
# at 107
#161109  9:07:51 server id 226  end_log_pos 175         Query   thread_id=7     exec_time=0     error_code=0
SET TIMESTAMP=1478653671/*!*/;
SET @@session.pseudo_thread_id=7/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1344274432/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 175
#161109  9:07:51 server id 226  end_log_pos 289         Query   thread_id=7     exec_time=0     error_code=0
use `test`/*!*/;
SET TIMESTAMP=1478653671/*!*/;
INSERT INTO `pwd` (`pwd`, `no`) VALUES (1, 111)
/*!*/;
# at 289
#161109  9:07:51 server id 226  end_log_pos 316         Xid = 20
COMMIT/*!*/;
# at 316
#161109  9:19:35 server id 226  end_log_pos 384         Query   thread_id=4     exec_time=0     error_code=0
SET TIMESTAMP=1478654375/*!*/;
BEGIN
/*!*/;
# at 384
#161109  9:19:20 server id 226  end_log_pos 483         Query   thread_id=4     exec_time=0     error_code=0
SET TIMESTAMP=1478654360/*!*/;
insert into pwd values (2,11111)
/*!*/;
# at 483
#161109  9:19:35 server id 226  end_log_pos 510         Xid = 41
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

 

mysql 命令行操作1