1. 程式人生 > 其它 >Ubuntu 環境變數載入

Ubuntu 環境變數載入

1.通過root賬號登陸資料庫

mysql -uroot -p

然後輸入root賬號密碼

2.建立新使用者,並授權該使用者可以操作的資料庫和表

grant all privileges on 資料庫名.表名 to '使用者名稱'@'主機名' identified by '密碼' with grant option;
flush privileges;

資料庫名:如果為*,表示所有資料庫

表名:如果為*,表示所有表

*.*表示root許可權,即滿許可權

主機名:localhost表示僅允許本地連線,%表示本地和遠端均可連線

flush privileges;表示重新整理許可權,使授權生效

所以允許遠端連線的時候可以使用:

grant all privileges on *.* to 'root'@'%' identified by 'root賬號密碼' with grant option;

比如我們新建test使用者,授予該使用者的許可權是僅能操作test_database資料庫,密碼‘123’

grant all privileges on test_database.* to 'test'@'%' identified by '123' with grant option;

3.如何修改使用者密碼

  • root賬號登陸
mysql -u root -p
  • 使用mysql資料庫
use mysql;
  • 檢視user表
select host,user,authentication_string from user;

結果如下:

+-----------+------------------+-------------------------------------------+
| host      | user             | authentication_string                     |
+-----------+------------------+-------------------------------------------+
| localhost | root             | *6C2FC1038AB41E3B2B6D85B409E0F2B9C11BC8D3 |
| localhost | mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | debian-sys-maint | *E73AA584982C771D0F8B40367F92049530E668D4 |
| %         | root             | *6C2FC1038AB41E3B2B6D85B409E0F2B9C11BC8D3 |
| %         | test             | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+-----------+------------------+-------------------------------------------+
  • 修改使用者密碼:
update user set authentication_string = password(‘新密碼’) where user = '使用者名稱' and host = '主機名';

password()為mysql自身的一個加密函式

以修改test使用者密碼為'456'為例

update user set authentication_string = password('456') where user = 'test' and host = '%';

4.如何撤銷使用者許可權

revoke all on 資料庫名.表名 from '使用者名稱'@'主機名';

5.如何刪除使用者

drop user '使用者名稱'@’主機名‘;