MySQL常用命令

#Linux安装mysql
sudo apt install mysql-server mysql-client

#Linux配置msyql_connection_jar for java
cp mysql_connection_jar to /usr/local/jdkxx_xx/jre/ext/

#命令行登录mysql
mysql -u username -p 
mysql -u root -p -S /var/run/mysqld/mysqld.sock

#显示系统中的数据库
show databases;

#进入某一个数据库
use database_name;

#列出数据库中所有table
show tables;

#创建table
create table table_name(id VARCHAR(10), name VARCHAR(10));

#显示table信息
show columns from table_name;
describe table_name;

#显示主键(只对唯一主键有效,多个无效)
select _rowid from singers;

#查询
select * from table_name;
select distinct column_name from  databaseName.tableName
select count(*) from table_name

#插入数据
insert into table value("113","Jay");


#查询表相关信息
show table status like 'singers' \G

#查看数据库快照
mysqldump -u root -p QQSpider > zhangjie.txt

#查看table的索引
show index from table_name;

#添加索引
alter table_name add index()
create index_name on table_name(table_column)
alter table_name drop index index_name

#查看索引
show index from table_name;


#设置当前会话(Session)事务隔离级别
set session tx_isolation='READ-UNCOMMITTED';
set session tx_isolation='READ-COMMITTED';
set session tx_isolation='REPEATEABLE READ';
set session tx_isolation='SERIALIZED';
set @@tx_isolation='READ-COMMITTED';
#查询 
select &&tx_isolation



#分析某条查询语句执行的情况
explain select * from table_name


#查询数据库指定所在路径
show variables like 'datadir';

#查询配置文件所在路径
mysql --help | grep my.cnf

#查询存储引擎
show engines;

#复制一个table
create table table_2 as select * from table_1;

#强制使用索引来查询
select * from use index(a) where a =1 and b =2;
select * from force index(a) where a =1 and b =2;

#查看当前处理进程
show processlist

你可能感兴趣的:(Linux,MySQL)