Mysql数据库中创建、删除用户并授权给数据库
May 23, 2016 7:19 PM
创建用户
mysql > insert into mysql.user(Host,User,Password) values("localhost","user1",password("123456"));
mysql > create user 'user2'@'%' identified by '123456';
“%” 表示对所有非本地主机授权,不包括localhost
给用户授权
#对testdb数据库授予所有权限
mysql > grant all on testdb.* to 'user1'@'%' identified by '123456';
#部分授权
mysql > grant seletc,update on testdb.* to 'user1'@'%' identified by '123456';
修改用户密码
1.mysql > update mysql.user set password=password('newpassword') where User="user2" and Host="%";
mysql > flush privileges;
2.mysql > SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
mysql > flush privileges;
删除用户
delete from mysql.user where User='user2' and Host='%';
mysql > flush privileges; #刷新系统权限表
- 删除账户及权限:>drop user 用户名@’%’;
查看数据库中所有用户
mysql > select user,host from mysql.user;
查看数据库中具体某个用户的权限
mysql> show grants for user1;
mysql> show grants for 'username'@'%';
列出所有数据库
mysql > show databases;
创建数据库
mysql > create database db_name;
切换数据库
mysql > use '数据库名';
- 查看数据库编码:> show create database dbname;
列出所有表
mysql > show tables;
创建表
mysql > create table tb_name;
查看表结构
1.mysql> desc mysql.user; #desc=describe
2.mysql> show create table tablename;
删除数据库和数据表
mysql > drop database 数据库名;
mysql > drop table 数据表名;
收集整理自互联网