设为首页 加入收藏

TOP

mysql新添加用户与删除用户具体操作命令
2015-07-24 10:42:42 来源: 作者: 【 】 浏览:1
Tags:mysql 添加 用户 删除 具体 操作 命令
方法1 :使用mysql root(root权限)用户登陆直接赋权也可以创建用户
/usr/bin/mysqladmin -u root password 123456


mysql -uroot -p
密码
查看所有用户名与密码
select host ,user ,password from user;

grant all on ec.* to 'root'@'%' identified by '123456';
grant all privileges on ec.* to 'cockpit'@'%' identified by '123456';
grant all on ec.* to 'cockpit'@'%' identified by '123456';
grant all privileges on ec.* to 'cockpit'@'%' identified by '123456';
flush privileges;;

更改 数据库密码
user mysql

修改my sql数据库的密码
UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql root密码为空 登陆的时候不需要密码
UPDATE user SET Password=PASSWORD(null) where USER='root';
flush privileges;

方法二:
1.新建用户。
//登录MYSQL
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(testDB)
mysql>create database testDB default character set utf8;;
//创建用户
mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
//刷新 系统权限表
mysql>flush privileges;
这样就创建了一个名为:test 密码为:1234 的用户。
然后登录一下。
mysql>exit;
@>mysql -u phplamp -p
@>输入密码
mysql>登录成功
2.为用户授权。
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"; 
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234";

授权test用户拥有所有数据库的某些权限:  
  mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

//test用户对所有数据库都有select,delete,update,create,drop 权限。

  //@"%" 表示对所有非本地主机授权,不包括localhost。(localhost地址设为127.0.0.1,如果设为真实的本地地址,不知道是否可以,没有验证。)

//对localhost授权:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。

3.删除用户。
@>mysql -u root -p
@>密码
mysql>DELETE FROM user WHERE User="test" and Host="localhost";
mysql>flush privileges;
//删除用户的数据库
mysql>drop database testDB;
4.修改指定用户密码。
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password('新密码') where User="test" and Host="localhost";
mysql>flush privileges;

delete from user where User="test" and Host="localhost";

也可以试试:

删除账户及权限:>drop user 用户名@'%';

        >drop user 用户名@ localhost;

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQLServer排名函数 下一篇Mysql书库的导入(图文解析)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·HyperText Transfer (2025-12-26 07:20:48)
·半小时搞懂 HTTP、HT (2025-12-26 07:20:42)
·CPython是什么?PyPy (2025-12-26 06:50:09)
·Python|如何安装seab (2025-12-26 06:50:06)
·python要学习数据分 (2025-12-26 06:50:03)