本文摘自PHP中文网,作者php中世界最好的语言,侵删。
在日常的网站维护和MYSQL数据库管理中,我们经常会用到非常多的MYSQL命令,为了方便大家整理,小编列举了18个管理MYSQL数据库时最常使用的命令。在日常的网站维护和管理中,会用到非常多的SQL语句,
熟练使用对网站管理有很多好处,尤其是站群管理的时候。
下面列一些常用的命令做备记。
1、显示数据库
show databases
显示表
show tables;
2、创建用户
创建root用户密码为123
1 2 3 | use mysql;
grant all on *.* to root@ '%' identified by '123' with grant option;
commit;
|
3、修改密码
1 2 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:
5、预防性创建数据库:
1 | create database if not testdb;
|
6、创建表:
1 2 3 4 | use testdb;
create table table1(
username varchar(12),
password varchar(20));
|
7、预防性创建表aaa:
1 | create table if not exists aaa(ss varchar(20));
|
8、查看表结构:
9、插入数据到表table1:
1 2 3 4 | insert into table1(username,password) values
( 'leizhimin' , 'lavasoft' ),
( 'hellokitty' , 'hahhahah' );
commit;
|
10、查询表table1:
11、更改数据:
1 2 | update table1 set password= 'hehe' where username= 'hellokitty' ;
commit;
|
12、删除数据:
1 2 | delete from table1 where username= 'hellokitty' ;
commit;
|
13、给表添加一列:
1 2 3 4 5 | alter table table1 add column(
sex varchar(2) comment '性别' ,
age date not null comment '年龄'
);
commit;
|
14、修改表结构
从查询创建一个表table1:
1 2 | create table tmp as
select * from table1;
|
15、删除表table1:
1 2 | drop table if exists table1;
drop table if exists tmp;
|
16、备份数据库testdb
1 | mysqldump -h 192.168.3.143 -u root -p pwd -x --default-character- set =gbk >C:\testdb.sql
|
17、删除数据库testdb
18、恢复testdb数据库
首先先建立testdb数据库,然后用下面命令进行本地恢复
1 | mysql -u root -pleizhimin testdb <C:\testdb.sql
|
这18个MYSQL命令都是管理员在日常维护中经常会用到的,熟练使用这些命令会使你的工作非常轻松
相关推荐:
教你使用MySQL:MySQL常用命令一览_PHP教程
MYSQL常用命令与实用技巧
MySQL常用命令行总结收集
以上就是18个常用的MySQL命令的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
详解mysql函数拼接查询concat函数的使用方法
mysql两种引擎的有什么区别
mysql怎么查看有没有索引?
如何在mysql中创建和删除数据库
如何去除mysql表中的 r n
mysql数据库面试必备之三大log介绍
mysql大量写入问题优化详解
怎么将mysql服务移除?
计算机二级mysql考什么内容?
关于mysql性能调优你必须了解的15个重要变量(小结)
更多相关阅读请进入《mysql》频道 >>
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » 18个常用的MySQL命令