MYSQL常用命令
时间:2021-07-01 10:21:17
帮助过:29人阅读
MYSQL常用命令
1-启动Mysql
systemctl start mysqld

2-获取安装时的临时密码: 3>2X-WNr6aal
grep ‘temporary password‘ /var/log/mysqld.log
倘若没有:(1)删除原来安装过的mysql残留的数据
rm -rf /var/lib/mysql
2)再启动mysql

3-登录
mysql -u root -p

4-修改密码
set password=password("yourpassword")

5-数据库常用命令
查看数据库
show databases;

创建数据库
create database jfedu;

进入数据库
use jfedu;
显示数据库表
show tables;

创建名为t1表,并创建两个字
create table t1 (id varchar(20),name varchar(20));

向表中插入数据
insert into t1 values("1","jfedu");

查看t1表数据内容
select
from t1;

id,age多条件查询
select from t1 where id=1 and age=‘jfedu‘;
查看t1表数据内容
desc t1

修改name字段长度
alter table t1 modify column name varchar(20);
update t1 set name=‘jfedu.net‘ where id=1;
刷新权限
flush privileges;

清空表内容
delete table t1;

清空表
drop table t1;

删除test数据库
drop database test;

查看数据库字符集
show variables like ‘%char%‘;

查看MYSQL存储引擎
show engines;

查看数据库的默认引擎
show variables like ‘%storage_engine%‘;

修改MySQL t1表存储引擎。
alter table t1 engine=innodb;

6-MySQL数据字符集设置


vi /etc/my.cnf



7-MySQL数据库密管理
A-授权localhost主机通过test用户和pas密码访问本地的Jfedu库的所有权限
grant all on jfedu
to test@localhost identified by ‘pas‘;
B-授权所有主机通过test用户和pas密码访问本地的jfedu库的查询、插入、更新、删除权限。
grant select,insert,update,delete on .
to test@"%" identified by ‘pas‘;
C-授权192.168.1.11主机通过test用户及pas密码访问本地的jfedu库的所有权限。
grant all on jfedu to test@‘192.168.1.11‘ identified by ‘pas‘;
8-Mysql数据库密码破解方法
停止MySQL服务
systemctl stop mysqld
/etc/init.d/mysqld stop
。。
9-添加索引



10-MySQL数据库慢查询
show variables like "%slow%";

show variables like "%long_query%";

开启MySQL慢查询日志方法一
set global slow_query_log=on;

show variables like "%slow%";

开启MySQL慢查询日志方法二
vi /etc/my.cnf
添加以下内容
log-slow-queries = /data/mysql/localhost.log
long_query_time = 0.01
log-queries-not-using-indexes
11-慢查询mysqldumpslow -h查看帮助信息
按返回的行数从大到小,查看前2行,命令
mysqldumpslow -s r -t 2 localhost.log
按照查询总时间从大到小,查看前5行,同时过滤select的SQL语句
mysqldumpslow -s t -t 5 -g "select" localhost.log
MYSQL常用命令
标签:oba 密码破解 显示 所有权限 variable gre ora test like