mysql使用者及其密碼存取權限的設定(建立,刪除,修改)

來源:互聯網
上載者:User

標籤:

1.       CREATE USER文法:CREATE USER ‘username‘@‘host‘ IDENTIFIED BY ‘password‘;   例子: CREATE USER ‘dog‘@‘localhost‘ IDENTIFIED BY ‘123456‘;               CREATE USER ‘pig‘@‘192.168.1.101_‘ IDENDIFIED BY ‘123456‘;               CREATE USER ‘pig‘@‘%‘ IDENTIFIED BY ‘123456‘;               CREATE USER ‘pig‘@‘%‘ IDENTIFIED BY ‘‘;               CREATE USER ‘pig‘@‘%‘;     執行個體1:       mysql> create user jss;         這樣建立的使用者,可以從任意安裝了mysql用戶端,並能夠訪問目標伺服器的機器上建立串連,無須密碼.例如,從ip:10.0.0.99的用戶端執行串連:         mysql -ujss -h 172.16.1.110        查看該使用者:         mysql> select user,host,password from user where user=‘jss‘;                SELECT USER();    //顯示目前使用者     執行個體2:        mysql> create user jss_ps identified by ‘jss‘;                    使用者串連時,必須指定密碼,那就可以在建立使用者時,通過指定identified by子句來設定密碼       用密碼登陸:         mysql -ujss_ps -p -h 172.16.1.110      如果希望指定的使用者只能從某台指定的域(domain)或主機訪問,可以在建立使用者時指定host,例如,指定使用者只能從10.0.0.99訪問mysql> create user [email protected]10.0.0.99 identified by password ‘123456‘; 2.       使用GRANT語句文法:mysql> grant 許可權1,許可權2,...許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者地址 identified by ‘串連口令‘;許可權1,許可權2,...許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權執行個體:  mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected]10.163.225.87 identified by ‘123‘;給來自10.163.225.87的使用者joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。mysql>grant all privileges on vtdc.* to [email protected]10.163.225.87 identified by ‘123‘;給來自10.163.225.87的使用者joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。mysql>grant all privileges on *.* to [email protected]10.163.225.87 identified by ‘123‘;給來自10.163.225.87的使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。mysql>grant all privileges on *.* to [email protected] identified by ‘123‘;給本機使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。3.       直接向mysql.user表插入記錄:mysql> insert into user (host,user,password) values (‘%‘,‘jss_insert‘,password(‘jss‘));mysql>flush privileges;   //重新整理系統許可權表4.       修改mysql使用者密碼方式:a.       使用mysqladmin文法:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼例如:mysqladmin -u root -p 123 password 456;b.       直接修改user表的使用者口令:文法:update mysql.user set password=password(‘新密碼‘) where User="phplamp" and Host="localhost";執行個體:update user set password=password(‘54netseek‘) where user=‘root‘;      flush privileges;c.       使用SET PASSWORD語句修改密碼:文法:SET PASSWORD FOR ‘username‘@‘host‘ = PASSWORD(‘newpassword‘);如果是當前登陸使用者用SET PASSWORD = PASSWORD("newpassword");執行個體:set password for [email protected]=password(‘‘);SET PASSWORD FOR name=PASSWORD(‘new password‘);SET PASSWORD FOR ‘pig‘@‘%‘ = PASSWORD("123456");5.        刪除使用者和撤銷許可權:a.       取消一個賬戶和其許可權Drop USER user;drop user [email protected]‘%‘drop user [email protected]b.       取消授權使用者:文法:REVOKE privilege ON databasename.tablename FROM ‘username‘@‘host‘;例子: REVOKE SELECT ON *.* FROM ‘pig‘@‘%‘;  REVOKE SELECT ON test.user FROM ‘pig‘@‘%‘;  revoke all on *.* from [email protected] ;  revoke all on user.* from ‘admin‘@‘%‘;      SHOW GRANTS FOR ‘pig‘@‘%‘;     //查看授權c.       刪除使用者:文法: Delete from user where user = "user_name" and host = "host_name" ;例子:delete from user where user=‘sss‘ and host=‘localhost‘; 

 

mysql使用者及其密碼存取權限的設定(建立,刪除,修改)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.