本文目錄一覽:
linux用命令怎麼修改mysql用戶的權限
mysql更改用戶權限
This entry was posted by admin Monday, 26 April, 2010
1.「grant all on *.* to root@』%』 identified by 『yourpassword』;」——這個還可以順帶設置密碼。
2.「flush privileges; 」——刷新一下,讓權限生效。
mysql的一些其他的管理,可以用mysqladmin命令。可以用來設置密碼什麼的。
grant方面的詳細信息可以看我下面的轉載:
本文實例,運行於 MySQL 5.0 及以上版本。
MySQL 賦予用戶權限命令的簡單格式可概括為:
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@』%』
windows和Linux下的mysql授權表設置攻略
在Windows中,當mysql安裝完成之後不需要創建數據目錄和授權表。在數據目錄下的MySQL數據庫中存在一套預初始化的’賬戶的授權表。不要運行Unix中使用的mysql_install_db腳本。
在Unix上安裝MySQL後,需要初始化授權表、啟動服務器,並確保服務器工作正常。並為授權表中的賬戶指定密碼。
在Unix中,由mysql_install_db設置授權表。
如果系統為安裝好的CentOS5,則只需要運行
# mysql_install_db –user=mysql –datadir=/var/lib/mysql_ndbd/
一定要確保由mysql登錄賬戶擁有數據庫目錄和文件,以便在以後運行服務器具有讀、寫訪問權限。
當然,也可以以
mysqld_safe –user=mysql –skip-grant-tables 跳過授權表來登錄,登錄進去重新賦權限,同時更新權限表:flush privileges
linux mysql 數據庫權限
hi 樓主,在數據庫中創建包含很多,視圖,索引,臨時表的創建權限都能分開賦予,你可以執行 show privileges 來查看權限參數,我這邊就以創建表為例,只包含查詢表功能,其他修改,刪除,備份沒有權限;以下是步驟:
1,create user ‘tom’@’%’ identified by ‘123456’;—創建用戶,無權限;
2, grant create,select on wangxh2.* to tom;—–把wangxh2庫的所有表的創建和查詢賦予tom
3,flush privileges;—–刷新權限表才能起效
接下來是測試:
mysql show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| test |
| wangxh2 |
+——————–+
3 rows in set (0.06 sec)
mysql use wangxh2
Database changed
mysql show tables;
+——————-+
| Tables_in_wangxh2 |
+——————-+
| test |
+——————-+
1 row in set (0.00 sec)
mysql drop test;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘test’ at line 1
mysql drop table test;
ERROR 1142 (42000): DROP command denied to user ‘tom’@’localhost’ for table ‘test’
mysql select count(*) from test;
+———-+
| count(*) |
+———-+
| 33554432 |
+———-+
1 row in set (0.01 sec)
mysql insert into test values(1);
ERROR 1142 (42000): INSERT command denied to user ‘tom’@’localhost’ for table ‘test’
mysql delete from test;
ERROR 1142 (42000): DELETE command denied to user ‘tom’@’localhost’ for table ‘test’
mysql update test set id=1;
ERROR 1142 (42000): UPDATE command denied to user ‘tom’@’localhost’ for table ‘test’
mysql create table test1 (id int);
Query OK, 0 rows affected (0.02 sec)
mysql insert into test1 values(1);
ERROR 1142 (42000): INSERT command denied to user ‘tom’@’localhost’ for table ‘test1’
[mysql@localhost ~]$ mysqldump -u tom -paidengshan wangxh2 /home/mysql/aa.sql
mysqldump: Got error: 1044: Access denied for user ‘tom’@’%’ to database ‘wangxh2’ when using LOCK TABLES
[mysql@localhost ~]$
—————————————————————————————–
以上測試發現,tom對wangxh2有建表,查詢表的權限,但是修改,刪除,新增,備份都沒有權限,達到你的需求了
原創文章,作者:B1XVL,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/127518.html