莫道君行早,更有早行人。
一、事务的基本要素(ACID)
1、原子性(Atomicity):事务开始后所有操作,要么全部做完,要么全部不做,不可能停滞在中间环节。事务执行过程中出错,会回滚到事务开始前的状态,所有的操作就像没有发生一样。也就是说事务是一个不可分割的整体,就像化学中学过的原子,是物质构成的基本单位。
2、一致性(Consistency):事务开始前和结束后,数据库的完整性约束没有被破坏 。比如A向B转账,不可能A扣了钱,B却没收到。
3、隔离性(Isolation):同一时间,只允许一个事务请求同一数据,不同的事务之间彼此没有任何干扰。比如A正在从一张银行卡中取钱,在A取钱的过程结束前,B不能向这张卡转账。
4、持久性(Durability):事务完成后,事务对数据库的所有更新将被保存到数据库,不能回滚。
二、事务的并发问题 ……
三、MySQL事务隔离级别 ……
本人由于root密码设置太复杂,距离买云服务器过去好长时间,记不起来了,只好重置密码。
编辑配置文件/etc/my.cnf,在 [mysqld] 段加入一行:skip-grant-tables
如下:
[mysqld]
skip-grant-tables
skip-ssl
port = 3306
......
执行重启指令:service mysqld restart
[root@centos ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL... SUCCESS!
重启成功后,即可免密码登录root用户:mysql -u root
[root@centos ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
登录成功后,执行SQL更改root密码(假设为123456):
UPDATE mysql.user SET authentication_string = PASSWORD('123456') WHERE User = 'root';
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('123456') WHERE User = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1mysql>
注意上面的SQL语句,在5.7版本后,原来的密码字段名称Password改成了authentication_string。
退出mysql控制台,把添加到/etc/my.cnf配置文件的 skip-grant-tables 这行删除,再重启服务:service mysqld restart。之后,我们就可以使用新密码登录了。
[root@centos ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>