我们今天是要和大家一起探讨的是MySQL添加授权的用户命令 ,我前两天在相关网站看见MySQL添加授权的用户命令的资料,觉得挺好,就拿出来供大家分享。希望会给你带来一些帮助在此方面。 1.新建用户。 登录MySQL @MySQL -u root -p @密码 创建用户 MySQL mysql
我们今天是要和大家一起探讨的是MySQL添加授权的用户命令 ,我前两天在相关网站看见MySQL添加授权的用户命令的资料,觉得挺好,就拿出来供大家分享。希望会给你带来一些帮助在此方面。
1.新建用户。
登录MySQL
@>MySQL -u root -p
@>密码
创建用户
<ol class="dp-xml"> <li class="alt">MySQL<span class="tag">></span> mysql<span class="tag">></span> insert into MySQL.user(Host,User,Password,ssl_cipher,x509_issuer,x509_sub </li> <li><span>ject) values("localhost","pppadmin",password("passwd"),'','',''); </span></li> </ol>
这样就创建了一个名为:phplamp 密码为:1234 的用户。
然后登录一下。
<ol class="dp-xml"> <li class="alt">MySQL<span><span class="tag">></span><span>exit; </span></span> </li> <li> <span>@</span><span class="tag">></span>MySQL<span> -u phplamp -p </span> </li> </ol>
@>输入密码
MySQL>登录成功
2.为用户授权。
登录MySQL添加授权(有ROOT权限)。我里我以ROOT身份登录.
@>MySQL -u root -p
@>密码
首先为用户创建一个数据库(phplampDB)
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>create database phplampDB; </span></span> </li></ol>
授权phplamp用户拥有phplamp数据库的所有权限。
<ol class="dp-xml"><li class="alt"><span><span class="tag">></span><span>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234'; </span></span></li></ol>
刷新系统权限表
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>flush privileges; </span></span> </li></ol>
MySQL添加授权>其它操作
/*
如果想指定部分权限给一用户,可以这样来写:
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>grant select,update on phplampDB.* to phplamp@localhost identified by '1234'; </span></span> </li></ol>
刷新系统权限表。
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>flush privileges; </span></span> </li></ol>
*/
3.删除用户。
@>MySQL -u root -p
@>密码
<ol class="dp-xml"> <li class="alt">MySQL<span><span class="tag">></span><span>Delete FROM user Where </span><span class="attribute">User</span><span>=</span><span class="attribute-value">"phplamp"</span><span> and </span><span class="attribute">Host</span><span>=</span><span class="attribute-value">"localhost"</span><span>; </span></span> </li> <li>MySQL<span class="tag">></span><span>flush privileges; </span> </li> </ol>
删除用户的数据库
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>drop database phplampDB; </span></span> </li></ol>
4.修改指定用户密码。
@>MySQL -u root -p
@>密码
<ol class="dp-xml"> <li class="alt">MySQL<span class="tag">></span>update MySQL<span>.user set </span><span class="attribute">password</span><span class="attribute-value">password</span><span>=password('新密码') where </span><span class="attribute">User</span><span>=</span><span class="attribute-value">"phplamp"</span><span> and </span><span class="attribute">Host</span><span>=</span><span>"localhost"; </span> </li> <li>MySQL<span class="tag">></span><span>flush privileges; </span> </li> </ol>
5.列出所有数据库
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>show database; </span></span> </li></ol>
6.切换数据库
MySQL>use '数据库名';
7.列出所有表
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>show tables; </span></span> </li></ol>
8.显示数据表结构
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>describe 表名; </span></span> </li></ol>
9.删除数据库和数据表
<ol class="dp-xml"><li class="alt">MySQL<span><span class="tag">></span><span>drop database 数据库名; </span></span> </li></ol>
MySQL>drop table 数据表名; Tag标签: MySQL添加授权命令