转载自http://blog.youkuaiyun.com/aaidong/article/details/45074443
注意:以下操作都是在连接数据库之后,进入mysql环境,之后执行的命令都必须带有分号“;”
1.新增用户 授权
格式如下:
grant 操作权限 on 数据库.* to test1@"%" identified by "abc";
意思是:授予,某主机上的某用户(附带该用户的登录密码)在某数据库上,执行某些操作的权限
(1)比如:任意主机上(“%”),用户(用户名:test1,密码:adc)在所有数据库上,执行任意操作的权限(危险哦)
grant all privileges on *.* to test1@"%" identified by “abc”;
其中all privileges表示查询、插入、修改、删除的权限:select、insert、update、delete
以上命令等价于:
grant select,insert,update,delete on *.* to test1@"%" identified by "abc";
然后刷新权限
flush privileges;
(2)比如:授权本地主机上的用户操作数据库的权限
创建数据库(比如:openfire)
create database openfire;
授予本地主机用户 (用户名:test1,密码:test1)访问数据库(数据库名称:openfire)的操作权限
grant all privileges on openfire.* test1@localhost identified by "test1";
flush privileges;
现在,就可以用新的用户,访问openfire数据库了。
2.更新指定账户的密码
用户名:test1,新密码:1234
update mysql.user set password=password('1234') where User="test1" and Host="localhost";
3.删除用户
先使用mysql数据库
use mysql;
删除mysql数据库中user表中的某个本地用户(test7)
delete from user where User="test7" and Host=“localhost”;
4.显示命令
(1)显示所有数据库列表
show databases;
注意:Mysql的系统信息都存储在mysql库中,比如:修改密码和新增用户,实际就是在这个库进行
(2)打开某个数据库(比如数据库:openfire);
use openfire;
(3)显示本库中的所有表
show tables;
(4)显示某表的结构
describe table1;
(5)建库
create database 库名;
(6)建表
use 库名;
create table 表名 (字段设定列表);
(7)删库
drop database 库名;
(8)删表
drop table 表名;
(9)将表中的记录清空
delete from 表名;
(10)显示表中的记录
select * from 表名;
5.附录
MySQL处理数据库和表的常用命令(适合新手)
http://www.php100.com/html/it/focus/2014/1028/7635.html
MySQL命令大全(适合需要时查询)
http://www.cnblogs.com/zhangzhu/archive/2013/07/04/3172486.html