mysql新添加使用者與刪除使用者具體操作命令,mysql具體操作

來源:互聯網
上載者:User

mysql新添加使用者與刪除使用者具體操作命令,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

修改mysql資料庫的密碼
 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;


登入資料庫,輸入:show databases; 顯示mysql、test, 再用grant命令增加使用者A並賦予許可權 怎刪除A使用者

mysql是系統資料庫,user表是授權表
你刪除了A的話,授權表裡就不存在A使用者了
當然你如果直接修改的user表的話要重新整理授權,修改才會生效,重新整理方法樓上說過了
 
MySQL怎授權一個自己的建立的使用者比如daitest建立新資料庫的權利?命令

慢慢看吧
mysql中可以給你一個使用者授予如select,insert,update,delete等其中的一個或者多個許可權,主要使用grant命令,用法格式為:
grant 許可權 on 資料庫物件 to 使用者
一、grant 普通資料使用者,查詢、插入、更新、刪除 資料庫中所有表資料的權利。
grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’
或者,用一條 mysql 命令來替代:
grant select, insert, update, delete on testdb.* to common_user@’%’

二、grant 資料庫開發人員,建立表、索引、視圖、預存程序、函數。。。等許可權。
grant 建立、修改、刪除 mysql 資料表結構許可權。
grant create on testdb.* to developer@’192.168.0.%’;
grant alter on testdb.* to developer@’192.168.0.%’;
grant drop on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 外鍵許可權。
grant references on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 暫存資料表許可權。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 索引許可權。
grant index on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 視圖、查看視圖原始碼 許可權。
grant create view on testdb.* to developer@’192.168.0.%’;
grant show view on testdb.* to developer@’192.168.0.%’;
grant 操作 mysql 預存程序、函數 許可權。
grant create routine on testdb.* to developer@’192.168.0.%’; - now, can show procedure status
grant alter routine on testdb.* to developer@’192.168.0.%’; - now, you can drop a procedure
grant execute on testdb.* to developer@’192.168.0.%’;

三、grant 普通 dba 管理某個 mysql 資料庫的許可權。
grant all privileges on testdb to dba@’localhost’
其中,關鍵字 “privileges” 可以省略。

四、grant 進階 dba 管理 mysql 中所有資料庫的許可權。
grant......餘下全文>>
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.