Mysql之使用者的建立

來源:互聯網
上載者:User

標籤:

1.Create User

        文法:CREATE USER ‘username‘@‘host‘ IDENTIFIED BY ‘password‘;

    eg:

           CREATE USER ‘pig‘@‘192.168.1.101‘ IDENDIFIED BY ‘123456‘;  // 這裡限定了可訪問的主機的ip為192.168.1.101

           CREATE USER ‘pig‘@‘%‘ IDENTIFIED BY ‘123456‘;    //表明任何主機都可以訪問

           create user jss; //可以從任意安裝了mysql用戶端,並能夠訪問目標伺服器的機器上建立串連,無須密碼

2.Grant語句

       文法:grant 許可權1,許可權2,...許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者地址 identified by ‘串連口令‘;

    eg:

          grant select,insert,update,delete,create,drop on mydb.user to [email protected] identified by ‘123‘;//給來自192.168.1.101的使用者admin分配可對資料庫mydb的user表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。

          grant all privileges on mydb.* to [email protected] identified by ‘123‘;//給來自192.168.1.101的使用者admin分配可對資料庫mydb所有表進行所有操作的許可權,並設定口令為123

          grant all privileges on *.* to [email protected]  identified by ‘123‘;//給來自192.168.1.101‘的使用者admin分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123

3.直接向表中插入資料

       insert into user (host,user,password) values (‘%‘,‘admin‘,password(‘123‘));

       flush privileges;   //重新整理系統許可權表

4.修改密碼

      4.1.使用mysqladmin

               文法:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼

               eg:

                    mysqladmin -u root -p 123 password 456;

      4.2.直接修改user表的使用者口令

               文法:update mysql.user set password=password(‘新密碼‘) where User="phplamp" and Host="localhost";

               eg:

                     update user set password=password(‘54netseek‘) where user=‘root‘;

                     flush privileges;   //重新整理一下系統許可權表

       4.3.使用SET PASSWORD語句修改密碼

                文法:SET PASSWORD FOR ‘username‘@‘host‘ = PASSWORD(‘newpassword‘);

                          如果是目前使用者則去掉FOR ‘username‘@‘host‘

5.取消賬戶和其授權

           Drop USER user;

           drop user [email protected]‘%‘

           drop user [email protected]

6.去掉許可權

      文法:REVOKE privilege ON databasename.tablename FROM ‘username‘@‘host‘;

             eg:

                 REVOKE SELECT ON test.user FROM ‘pig‘@‘%‘;

                 revoke all on user.* from ‘admin‘@‘%‘;

                 SHOW GRANTS FOR ‘pig‘@‘%‘;     //查看授權

7.刪除賬戶

           文法: Delete from user where user = "user_name" and host = "host_name" ;

            eg:

                 delete from user where user=‘admin‘ 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.