ERROR: index path not specified Usage: java org.apache.lucene.index.CheckIndex pathToIndex [-exorcise] [-crossCheckTermVectors] [-segment X] [-segment Y] [-dir-impl X]
-exorcise: actually write a new segments_N file, removing any problematic segments -fast: just verify file checksums, omitting logical integrity checks -crossCheckTermVectors: verifies that term vectors match postings; THIS IS VERY SLOW! -codec X: when exorcising, codec to write the new segments_N file with -verbose: print additional details -segment X: only check the specified segments. This can be specified multiple times, to check more than one segment, eg '-segment _2 -segment _a'. You can't use this with the -exorcise option -dir-impl X: use a specific FSDirectory implementation. If no package is specified the org.apache.lucene.store package will be used.
**WARNING**: -exorcise *LOSES DATA*. This should only be used on an emergency basis as it will cause documents (perhaps many) to be permanently removed from the index. Always make a backup copy of your index before running this! Do not run this tool on an index that is actively being written to. You have been warned!
Run without -exorcise, this tool will open the index, report version information and report any exceptions it hits and what action it would take if -exorcise were specified. With -exorcise, this tool will remove any segments that have issues and write a new segments_N file. This means all documents contained in the affected segments will be removed.
This tool exits with exit code 1 if the index cannot be opened or has any corruption, else 0.
$ git push Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 12 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 297 bytes | 297.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: error: refusing to update checked out branch: refs/heads/dev remote: error: By default, updating the current branch in a non-bare repository remote: is denied, because it will make the index and work tree inconsistent remote: with what you pushed, and will require 'git reset --hard' to match remote: the work tree to HEAD. remote: remote: You can set the 'receive.denyCurrentBranch' configuration variable remote: to 'ignore' or 'warn' in the remote repository to allow pushing into remote: its current branch; however, this is not recommended unless you remote: arranged to update its work tree to match what you pushed in some remote: other way. remote: remote: To squelch this message and still keep the default behaviour, set remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To file:///d/test/repository/git1/.git/ ! [remote rejected] dev -> dev (branch is currently checked out) error: failed to push some refs to 'file:///d/test/repository/git1/.git/'
mysql> SELECT VERSION(); +------------+ | VERSION() | +------------+ | 5.6.41-log | +------------+ 1 row in set (0.09 sec)
使用 SHOW VARIABLES
1 2 3 4 5 6 7
mysql> SHOW VARIABLES LIKE 'version'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.6.41-log | +---------------+------------+ 1 row in set (0.14 sec)
查看事务隔离级别
查看当前会话的事务隔离级别
1 2 3 4 5 6 7
mysql> SELECT @@SESSION.tx_isolation; +------------------------+ | @@SESSION.tx_isolation | +------------------------+ | READ-COMMITTED | +------------------------+ 1 row in set (0.07 sec)
读已提交 READ-COMMITTED
查看全局事务隔离级别
1 2 3 4 5 6 7
mysql> SELECT @@GLOBAL.tx_isolation; +-----------------------+ | @@GLOBAL.tx_isolation | +-----------------------+ | READ-COMMITTED | +-----------------------+ 1 row in set (0.06 sec)
使用 SHOW VARIABLES
1 2 3 4 5 6 7
mysql> SHOW VARIABLES LIKE 'tx_isolation'; +---------------+----------------+ | Variable_name | Value | +---------------+----------------+ | tx_isolation | READ-COMMITTED | +---------------+----------------+ 1 row in set (0.08 sec)
使用事务
1 2 3 4 5 6 7 8 9 10
# 开启事务 START TRANSACTION;
# 执行操作A... # 执行操作B...
# 提交或回滚事务 COMMIT; ROLLBACK;
查看事务
1
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;
这条查询语句将返回一个表,显示所有当前活动的事务的信息,例如:
trx_id:事务 ID。
trx_state:事务状态(如 RUNNING、LOCK WAIT 等)。
trx_started:事务开始的时间。
trx_requested_lock_id:如果事务在等待锁定,则显示请求的锁定 ID。
trx_wait_started:如果事务在等待锁定,则显示等待开始的时间。
trx_mysql_thread_id:执行事务的 MySQL 线程 ID。
查看一个事务运行了多长时间:
1
SELECT TIMESTAMPDIFF(SECOND, t.trx_started, NOW()) AS trx_runtime_seconds,t.* FROM information_schema.INNODB_TRX t;
查看 INNODB_TRX 表的锁等待状态
INNODB_TRX 表包含当前正在执行的事务信息,通过它可以查看是否有事务处于等待锁的状态。
1 2 3 4 5 6 7 8 9 10 11
SELECT trx_id, trx_state, trx_started, trx_wait_started, TIMESTAMPDIFF(SECOND, trx_wait_started, NOW()) AS wait_time_seconds, trx_requested_lock_id FROM INFORMATION_SCHEMA.INNODB_TRX WHERE trx_state = 'LOCK WAIT';
trx_state = ‘LOCK WAIT’ 表示正在等待锁的事务。
wait_time_seconds 显示事务等待锁的时间。
如果有长时间等待锁的事务,可以怀疑存在潜在的死锁。
手动制造一个死锁
现在有一个表 test,有Id 和 v 两个字段,里面有两条数据 1,1;2,2
确保wait_timeout 时间足够长
步骤:
在第一个会话中,开始一个事务并锁定记录 id=1
1 2
START TRANSACTION; UPDATE test SET v = 11 WHERE id = 1;
在第二个会话中,开始另一个事务并锁定记录 id=2:
1 2
START TRANSACTION; UPDATE test SET v = 22 WHERE id = 2;
回到第一个会话,尝试更新记录 id=2(此时这个记录已被第二个事务锁定,导致第一个事务无法继续):
1
UPDATE test SET value = 12 WHERE id = 2;
回到第二个会话,尝试更新记录 id=1(此时这个记录已被第一个事务锁定,导致第二个事务无法继续):
1 2
UPDATE test SET v = 21 WHERE id = 1;
此时会报错,Mysql会检测到一个死锁错误:
1
1213 - Deadlock found when trying to get lock; try restarting transaction
MySQL 会自动检测到这个死锁,并回滚其中一个事务(通常是后发起的事务),这是 MySQL 中的一个重要特性,它能有效地避免数据库的无限期阻塞。
查当前正在运行的 MySQL 线程
使用 SHOW PROCESSLIST
SHOW PROCESSLIST 命令用于显示当前 MySQL 服务器中所有连接的信息。默认情况下,它会显示所有会话的状态,包括线程 ID、用户、主机、数据库、命令、时间、状态和查询等信息。
1 2
SHOW PROCESSLIST; SHOW FULL PROCESSLIST;
在 MySQL 5.6 及更高版本中,你可以使用 SHOW FULL PROCESSLIST 获取更详细的信息
使用 INFORMATION_SCHEMA.PROCESSLIST 视图
通过查询 INFORMATION_SCHEMA.PROCESSLIST 视图来实现更灵活的过滤
1 2
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST; SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE DB = 'test';
示例 显示所有运行时间超过 60 秒的查询:
1
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE TIME > 60;
显示所有正在等待锁的查询:
1
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE '%lock%';
只显示特定用户的会话:
1
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER = 'your_user';
显示所有非空闲会话:
1
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND != 'Sleep';