Home > Database > Mysql Tutorial > MySql增加用户、授权、修改密码等语句

MySql增加用户、授权、修改密码等语句

WBOY
Release: 2016-06-07 18:00:35
Original
1302 people have browsed it

MySql 新建用户,新建数据库,用户授权,删除用户,修改密码

1.新建用户。
//登录MYSQL
@>mysql -u root -p
@>密码
//创建用户
mysql> mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_sub
ject) values("localhost","pppadmin",password("passwd"),'','','');
这样就创建了一个名为:phplamp 密码为:1234 的用户。
然后登录一下。
mysql>exit;
@>mysql -u phplamp -p
@>输入密码
mysql>登录成功
2.为用户授权。
//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录.
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(phplampDB)
mysql>create database phplampDB;
//授权phplamp用户拥有phplamp数据库的所有权限。
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系统权限表
mysql>flush privileges;
mysql>其它操作
/*
如果想指定部分权限给一用户,可以这样来写:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系统权限表。
mysql>flush privileges;
*/
3.删除用户。
@>mysql -u root -p
@>密码
mysql>Delete FROM user Where User="phplamp" and Host="localhost";
mysql>flush privileges;
//删除用户的数据库
mysql>drop database phplampDB;
4.修改指定用户密码。
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";
mysql>flush privileges;
5.列出所有数据库
mysql>show database;
6.切换数据库
mysql>use '数据库名';
7.列出所有表
mysql>show tables;
8.显示数据表结构
mysql>describe 表名;
9.删除数据库和数据表
mysql>drop database 数据库名;
mysql>drop table 数据表名;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template