#连接数据库
mysql -uroot -ppassword
#MYSQL支持的引擎(InnoDB)
show engines;
#查看当前数据库
select database();
#查看MYSQL支持的引擎(InnoDB)
show engines;
#切换数据库
use spring;
#如何查看mysql的安装目录
show variables like "%char%";
#如何查看mysql数据库物理文件存放位置
show variables like "%data%";
#查看版本号
select version();
#查看当前事务自动提交开关配置(默认是 ON-1 自动提交; OFF-0 不是自动提交 需要手动 commit;)
show variables like 'autocommit';//默认查询当前会话下的
show session variables like 'autocommit';//查询当前会话下的
show global variables like 'autocommit';//查询全局的
select @@autocommit;
select @@session.autocommit;
select @@global.autocommit;
#设置当前事务自动提交开关
set autocommit=0;//设置当前会话下的,只对当前会话有效且立即生效,不需重新打开会话
set session autocommit=0;//设置当前会话下的,只对当前会话有效且立即生效,不需重新打开会话
set global autocommit=0;//设置全局的,只是全局变量值变了,当前会话下的不会立马跟着变的,要生效的话,需重新打开(不论当前窗口还是其他窗口)
#查看当前事务隔离级别:默认是 可重复读 repeatable read
#read uncommitted 读未提交; read committed 读已提交; repeatable read 可重复读; serializable 串行化;
show variables like "%iso%";
select @@transaction_isolation;
#设置当前事务隔离级别
set session transaction isolation level repeatable read;
#查看表结构
describes t3;
#事务开始
start transaction
begin
#事务提交
commit
#事务回滚
rollback
#使用 InnoDB 创建表
CREATE TABLE person(
id bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
score int(11) NOT NULL,
create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY name_score (name(191),score),
KEY create_time (create_time)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
#使用 MyISAM 创建表
CREATE TABLE person_myisam(
id bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
score int(11) NOT NULL,
create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY name_score (name(191),score),
KEY create_time (create_time)
)ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
#创建存储过程
CREATE PROCEDURE insert_person()
begin
declare c_id integer default 1;
while c_id<=100000 do
insert into person values(c_id,concat('name',c_id),c_id+100,date_sub(NOW(),interval c_id second));
set c_id=c_id +1;
end while;
end;
mysql常用命令锦集(持续更新ing)
于 2021-04-18 09:23:54 首次发布