mysql学习总结

本文详细介绍了MySQL数据库的基本操作,包括创建表、复制表结构、数据导入导出、备份还原、用户授权、表结构修改、索引创建与管理、以及SQL文件导入等核心功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql常用命令:


创建表A,复制表B的数据结构,(不复制数据)

create table A like B;


复制表B的数据内容到表A中(前提是表A与表B数据结构一致):

insert into A  select   *   from  B;


查看表A的创建语句:

show create table A;


查看表A的数据结构:

desc A;


将sql文件导入到数据库demo:

命令行进入demo数据库 mysql -uroot -p  demo;

输入密码进入后导入   source   /home/zfeig/test.sql;



mysql数据备份与还原

mysqldump -uroot  -h192.168.0.3 news > d:/data/news.sql;//备份数据库

mysqldump -uroot  -h192.168.0.3 news < d:/data/news.sql;//还原数据库



修改mysql的root用户密码:

update mysql.user  set password =password(***) where user="root";

flush privileges;

或者 mysql -u root password "XXXX";


修改mysql的表结构:

alter table A add title varchar(256) not null default ''; //添加字段

alter table A  drop time;//删除字段

alter table A modify id int(10) primary key  auto_increment;//修改字段类型

alter table A change title tiltes varchar(256) not null default '';更改字段名

alter table A rename B;//修改表名


mysql指定用户授权:

// 授权指定用户 所有数据库所有权限

grant all privileges on *.*  to  zfeig@localhost  identified by "123456";

flush privileges;


//授权指定用户某一数据库所有权限

grant all privileges on news.* to lisi@192.168.0.3 identified by "123456";

flush privileges;


//授权指定用户某一数据库部分权限

grant select,update,insert  on news.* to hua@192.168.0.4 identified by "123456";



创建索引
alter table news add index id_index(cid);


创建唯一索引
alter table news add unique cid_index(cid);


创建主键索引
alter table news add primary key(id);




查看索引
1、desc news;
2、show index from nerws;




删除索引
alter table news drop indx id_index;




将字段改为主键索引,并设置主键索引


alter table news modify id int(10) not null auto_increment;
alter table news add primary key(id);








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值