0%

Mac 常用命令记录

环境变量配置

1
2
3
4
5
6
# 1、默认配置环境变量都在 ~/.bash_profile文件中,升级后默认是不生效的 执行如下操作即可
vim ~/.zshrc
# 2、在.zshrc文件中增加
source $HOME/.bash_profile
# 3、然后在执行如下命令即可
source $HOME/.bash_profile

常用配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# jdk8
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH=$PATH:$JAVA_HOME
export JAVA_HOME
export CLASSPATH

# maven config
export M2_HOME=/Users/zhenglin/env/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin

# gradle配置
export PATH=$PATH:/Users/zhenglin/env/gradle-7.1.1/bin

# node配置
export PATH=$PATH:/Users/zhenglin/env/node-v14.15.0-darwin-x64/bin

# mongoDB配置
export PATH=$PATH:/usr/local/mongoDB/bin

常用命令

登录命令

1
$ mysql -h host -u root -p

查看表结构命令

1
2
3
4
5
6
7
desc tableName;

# 查看建表语句
show create table tableName;

# 查看表的定义
show table status like 'metrics' ;

事务隔离级别

1
2
3
4
$ select @@tx_isolation;

# 设置事务隔离级别
set session transaction isolation level read committed;

查看事务提交方式

1
2
3
4
# 注意 这里的1:是NO打开状态 0:OFF 状态
show variables like 'autocommit';
set autocommit = 1;
# 在一些版本中,mysql执行DDL语句前,会自动提交所有事务。

存储引擎

修改

1、Alter table tableName engine=’INNODB’;
2、导出表结构数据后,重新建表
3、创建一张新表,使用 insert into newTableName select * from OldTableName;(数据量较大、可以分段执行)

事务注意

1
# 同一个事务中,使用了两种存储引擎数据表,正常情况下没有什么问题,异常时非事务型数据表数据的修改不能正常回滚。

INDB 下的 MVCC

多版本并发控制

只在 REPEATABLE READ、READ COMMITTED 两种情况下工作

1
在每行记录后面增加两列数据,一列记录行的创建时间、一列记录行的删除时间。这里所谓的时间,是指系统版本号,每开始一个新的事务,系统版本号都会自定进行递增。
  1. SELECT: 基于两个条件 1、查找版本号早于当前系统版本号的数据 2、删除版本号未定义、或者大于当前事务版本号的数
  2. INSERT: 为新插入的每一行保存当前系统版本号作为插入版本号
  3. DELETE: 为删除的每一行插入当前系统版本号作为删除版本号
  4. UPDARE: 为新插入的每一行保存当前系统版本号作为插入版本号,同时保存系统版本号到原数据的删除行版本号中

Mysql 锁

两段锁,即加锁、解锁两段 属于隐式锁

显示锁

1
显式锁定是指使用 Select **** for update、select *** lock in share mode 这种锁定。

进程查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 查看进程
show processlist;
select * from information_schema.processlist;

# 显示用户正在运行的线程,
# 需要注意的是,除了 root 用户能看到所有正在运行的线程外,其他用户都只能看到自己正在运行的线程,看不到其它用户正在运行的线程。除非单独个这个用户赋予了PROCESS 权限。

# 垂直展示
show processlist \G;

# 查看那个客户端连接数量最多
select client_ip,count(client_ip) as client_num from (select substring_index(host,':' ,1) as client_ip from processlist ) as connect_info group by client_ip order by client_num desc;

# 查看长链接线程
select * from information_schema.processlist where Command != 'Sleep' order by Time desc;

# 查看长链接超过指定时间的线程
select concat('kill ', id, ';') from information_schema.processlist where Command != 'Sleep' and Time > 300 order by Time desc;

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment