2014-02-26 28 views
0

我想創建一個用戶在MySQL中擁有自己的數據庫的所有權限。MySQL創建表的問題 - 只讀錯誤

當我使用這個用戶創建一個表時,MySQL返回SQL服務器正在運行的只讀選項。

但是,當我更改爲*.*上的所有權限的另一個現有用戶時,我可以創建表而不會出錯。

我想知道,只讀選項是全球性的還是什麼?

下面是使用MySQL的root我的MySQL命令:

 
mysql> create user 'demo'@'localhost' identified by 'demo'; 
mysql> create database demo; 
mysql> grant all privileges on demo.* to [email protected]; 
mysql> show grants for [email protected]; 
+-------------------------------------------------------------------------------------------------------------------+ 
| Grants for [email protected]                     | 
+-------------------------------------------------------------------------------------------------------------------+ 
| GRANT USAGE ON *.* TO 'demo'@'localhost' IDENTIFIED BY PASSWORD '*demo-hashed*' | 
| GRANT ALL PRIVILEGES ON `demo`.* TO 'demo'@'localhost'            | 
+-------------------------------------------------------------------------------------------------------------------+ 
2 rows in set (0.00 sec) 

然後我切換到用戶「演示」:

 
mysql> use demo; 
Reading table information for completion of table and column names 
You can turn off this feature to get a quicker startup with -A 

Database changed 
mysql> create table t(t1 int); 
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement 

於是我查了只讀選項,它似乎開啓。

然而,我嘗試使用*.*特權的另一個用戶,我可以成功創建表。

的其他用戶授予設置:

 
mysql> show grants for [email protected]'%'; 
+-----------------------------------------------------------------------------------------------------------------+ 
| Grants for [email protected]%                       | 
+-----------------------------------------------------------------------------------------------------------------+ 
| GRANT ALL PRIVILEGES ON *.* TO 'demo2'@'%' IDENTIFIED BY PASSWORD '*demo2-hased*' | 
+-----------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.00 sec) 

MySQL版本:

 
mysql> select version(); 
+------------------------+ 
| version()    | 
+------------------------+ 
| 5.1.68.0 | 
+------------------------+ 
1 row in set (0.00 sec) 

順便說一句,在我設置read_only = 0我可以使用demo創建表。我只是不知道爲什麼demo2可以創建表,而只讀打開。

謝謝!

+0

你可以在兩個地方添加select current_user()。我發現的一個可能的原因是促使奴隸成爲主人。希望這不是你的情況 – georgecj11

+0

嘗試重新啓動mysql – PravinS

回答

4

請檢查Windows的My.cnf爲Linux或My.ini[mysqld]刪除只讀參數,然後重新啓動該服務,然後再試一次,這將解決只讀的問題,但如果你在閱讀創建表只,這將是一個臨時表。