常用的MySQL命令有哪些
这篇文章主要介绍常用的MySQL命令有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
在日常的网站维护和管理中,会用到非常多的SQL语句,
熟练使用对网站管理有很多好处,尤其是站群管理的时候。
下面列一些常用的命令做备记。
1、显示数据库
show databases
显示表
show tables;
2、创建用户
创建root用户密码为123
usemysql;grantallon*.*toroot@'%'identifiedby'123'withgrantoption;commit;
3、修改密码
grantallon*.*toxing@'localhost'identifiedby'123456'withgrantoption;updateusersetpassword=password('newpwd')whereuser='xing'andhost='localhost';flushprivileges;
4、创建数据库testdb:
createdatabasetestdb;
5、预防性创建数据库:
createdatabaseifnottestdb;
6、创建表:
usetestdb;createtabletable1(usernamevarchar(12),passwordvarchar(20));
7、预防性创建表aaa:
createtableifnotexistsaaa(ssvarchar(20));
8、查看表结构:
describetable1;
9、插入数据到表table1:
insertintotable1(username,password)values('leizhimin','lavasoft'),('hellokitty','hahhahah');commit;
10、查询表table1:
select*fromtable1;
11、更改数据:
updatetable1setpassword='hehe'whereusername='hellokitty';commit;
12、删除数据:
deletefromtable1whereusername='hellokitty';commit;
13、给表添加一列:
altertabletable1addcolumn(sexvarchar(2)comment'性别',agedatenotnullcomment'年龄');commit;
14、修改表结构
从查询创建一个表table1:
createtabletmpasselect*fromtable1;
15、删除表table1:
droptableifexiststable1;droptableifexiststmp;
16、备份数据库testdb
mysqldump-h192.168.3.143-uroot-ppwd-x--default-character-set=gbk>C:\testdb.sql
17、删除数据库testdb
dropdatabasetestdb;
18、恢复testdb数据库
首先先建立testdb数据库,然后用下面命令进行本地恢复
mysql-uroot-pleizhimintestdb<C:\testdb.sql
这18个MYSQL命令都是管理员在日常维护中经常会用到的,熟练使用这些命令会使你的工作非
以上是“常用的MySQL命令有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。