mysql常用命令集合 及附图操作

按电脑左下角window图标 找到添加的mysql(如果要经常使用 右击打开文件位置 找到该文件 右击发送到桌面快捷方式 就行)

1.1打开mysql 输入你安装时定下的密码

 

1.2创建用户

--创建用户

create user "tqn"@"localhost"  identified by "1234";

1.3使用此数据库

--使用数据库

use mysql --用户保存在mysql数据库中

1.4查看表格

--查询表

show tables;

1.5查询用户

--查询用户

select user from user;

1.6修改密码格式的两种 看你的系统支持哪个

--修改密码

set password  for "tqn"@"localhost" = PASSWORD("12345");

set password  for "tqn"@"localhost" = "12345";

1.7mysql 授权语句报错 原因是show本身就有不需要二次授权

--授权操作(指定用户可以)

grant insert, show, update on *.*to "tqn"@"localhost";

grant insert, update on *.*to "tqn"@"localhost";

1.8删除用户 然后查询用户 记得要加分号啊!

--删除用户

drop user "tqn"@"localhost";

1.9查看数据库

--查询数据库

show databases;

 

 

2.1创建一个数据库

-- 创建数据库
create database xxxx;

-- 删除数据库
drop databse xxxx;

2.2查看数据库

2.3使用自己创建的这个数据库

--
use mydatabase;

2.4创建student表

-- 创建表(tinyint -128+127)
create table student(
id int unsigned not null primary key auto_increment,
name char(10) not null,
age tinyint unsigned not null );

或者

-- 创建表(tinyint - 128 + 127)(支持中文格式的char字符输入)
create table student(
    id int unsigned not null primary key auto_increment,
    name char(10) not null,
    age tinyint unsigned not null) charset utf8;

2.5查看表结构

-- 查看表结构
describe student;

2.6修改表 添加生日信息 加在id后面

-- 修改表 添加一个生日 加在id后面
alter table student add birthday date after id;

-- 查看表结构
describe student;

2.7删除id 查看一下

-- 删除id
alter table student drop id;

-- 查看表结构
describe student;

2.8再把id加回来 顺便加一个电话号码 默认11个杠 查看一下表信息

-- 再把它加回来
alter table student add id int unsigned not null primary key auto_increment first;

-- 添加电话 默认11个杠
alter table student add id char(11) default "-";

2.9重命名表格

-- 修改表的名字
alter table student rename stu;

3.1向表中插入数据 然后查看表的信息

-- 向表中插入信息
insert into student(id, birthday, name, age, tel) values(1, "1997-7-3", "张三", 20, "17766074507");

3.2表中插入信息的几种方式 有默认值的可以不写值 以默认值自动插入

-- 向表中插入信息
insert into stu(id, birthday, name, age) values(2, "1997-7-3", "李四", 20);

-- 向表中插入信息
insert into stu values
(3, "1997-7-3", "李四2", 20, "17766074512"),
(4, "1997-7-3", "李四3", 20, "17766074532");

3.3删除表中数据信息 条件可以自己想想

--删除数据
delete from student where id = 3;

--删除表
drop table xxxx;

猜你喜欢

转载自blog.csdn.net/qq_38313246/article/details/81662005