MySQL資料庫添加新使用者

來源:互聯網
上載者:User

在VPS上安裝完MySQL之後,預設的使用者只有root@localhost,新添加MySQL使用者最簡單的方法是:

在phpmyadmin裡面執行如下語句(語句最後要加分;號):

grant all privileges on DBNAME.* to USERNAME@localhost identified by 'PASSWORD'
flush privileges

當然在SSH裡面運行

mysql -uroot -p

之後也能夠輸入上面的sql語句,效果一樣。

解釋如下:

這將添加新使用者,使用者名稱稱是USERNAME,密碼是PASSWORD,這個使用者在DBNAME這個資料庫裡面有修改,讀取等許可權。

補充一篇思路更清楚添加使用者的方法

1 建立使用者

mysql -u root -p

輸入密碼

後進入mysql 命令列管理


insert into mysql.user(Host,User,Password) values('localhost','admin',password('123456'));


//重新整理系統許可權表

mysql> flush privileges;


2建立資料庫

create database newdatabase;


3為使用者授權

mysql>grant all privileges on newdatabase.* to admin@localhost identified by '123456';
mysql>flush privileges;


也可以授予該使用者特定的許可權

grant select, insert,update,delete on newdatabase.* to admin@localhost identified by '123456';


共14種許可權  select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file

mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的使用者joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to joe@localhost identified by ‘123′;
給本機使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.