zoukankan      html  css  js  c++  java
  • mysql新加入用户与删除用户详细操作命令

    方法1 :使用mysql root(root权限)用户登陆直接赋权也能够创建用户
    /usr/bin/mysqladmin -u root password 123456



    mysql -uroot -p
    password
    查看全部username与password
    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;;

    更改数据库password
    user mysql

    改动mysql数据库的password
     UPDATE user SET Password=PASSWORD('123456') where USER='root';
    mysql  rootpassword为空  登陆的时候不须要password
    UPDATE user SET Password=PASSWORD(null) where USER='root';
    flush privileges;

    方法二:
    1.新建用户。
    //登录MYSQL
    @>mysql -u root -p
    @>password
    //首先为用户创建一个数据库(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  password为:1234  的用户。
    然后登录一下。


    mysql>exit;
    @>mysql -u phplamp -p
    @>输入password
    mysql>登录成功
    2.为用户授权。


        格式:grant 权限 on 数据库.* to username@登录主机 identified by "password"; 
        >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
    @>password
    mysql>DELETE FROM user WHERE User="test" and Host="localhost";
    mysql>flush privileges;
    //删除用户的数据库
    mysql>drop database testDB;
    4.改动指定用户password。
    @>mysql -u root -p
    @>password
    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 username@'%';

            >drop user username@ localhost;

  • 相关阅读:
    IDEA 2021.1 推出语音、视频功能,边写代码边聊天
    HTML5实现首页动态视频背景
    前端项目自动化构建工具——Webpack入门教程
    JavaScript多线程及事件循环机制
    SVN迁移至Git,保留commit提交记录
    Windows平台下搭建自己的Git服务器
    SVN服务器搭建、备份及多服务器同步方案(Windows)
    全图文分析:如何利用Google的protobuf,来思考、设计、实现自己的RPC框架
    注册表修改右键菜单的说明
    powershell换行输出,换行输入命令,多行命令的执行
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7001010.html
Copyright © 2011-2022 走看看