常用的MySQL命令有哪些

发布时间:2021-01-15 11:38:56 作者:小新
来源:亿速云 阅读:106

这篇文章主要介绍常用的MySQL命令有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

在日常的网站维护和管理中,会用到非常多的SQL语句,
熟练使用对网站管理有很多好处,尤其是站群管理的时候。

下面列一些常用的命令做备记。

1、显示数据库
show databases
显示表
show tables;

2、创建用户
创建root用户密码为123

use mysql; 
grant all on *.* to root@'%' identified by '123' with grant option; 
commit;

3、修改密码

grant all on *.* to xing@'localhost' identified by '123456' with grant option; 
update user set password = password('newpwd') where user = 'xing' and host='localhost'; 
flush privileges;

4、创建数据库testdb:

create database testdb;

5、预防性创建数据库:

create database if not testdb;

6、创建表:

use testdb; 
create table table1( 
username varchar(12), 
password varchar(20));

7、预防性创建表aaa:

create table if not exists aaa(ss varchar(20));

8、查看表结构:

describe table1;

9、插入数据到表table1:

insert into table1(username,password) values 
('leizhimin','lavasoft'), 
('hellokitty','hahhahah'); 
commit;

10、查询表table1:

select * from table1;

11、更改数据:

update table1 set password='hehe' where username='hellokitty'; 
commit;

12、删除数据:

delete from table1 where username='hellokitty'; 
commit;

13、给表添加一列:

alter table table1 add column( 
 sex varchar(2) comment '性别', 
 age date not null comment '年龄' 
); 
commit;

14、修改表结构

从查询创建一个表table1:

create table tmp as 
select * from table1;

15、删除表table1:

drop table if exists table1; 
drop table if exists tmp;

16、备份数据库testdb

mysqldump -h 192.168.3.143 -u root -p pwd -x --default-character-set=gbk >C:\testdb.sql

17、删除数据库testdb

drop database testdb;

18、恢复testdb数据库
首先先建立testdb数据库,然后用下面命令进行本地恢复

mysql -u root -pleizhimin testdb <C:\testdb.sql

这18个MYSQL命令都是管理员在日常维护中经常会用到的,熟练使用这些命令会使你的工作非

以上是“常用的MySQL命令有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. mysql命令
  2. 常用MySQL命令详析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:SQL中distinc的使用方法

下一篇:mysql数据库中分页查询的使用方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》