今在服務(wù)器上 有mysql 數(shù)據(jù)庫,遠程訪問,不想公布root賬戶,所以,創(chuàng)建了demo賬戶,允許demo賬戶在任何地方都能訪問mysql數(shù)據(jù)庫中shandong庫。 方案一: 在安裝mysql的機器上運行: 1: 創(chuàng)建user用戶 復(fù)制代碼 代碼如下: CREATE USER demo IDENTIFIED BY “123456”
2、 復(fù)制代碼 代碼如下: mysql>GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'WITH GRANT OPTION //賦予任何主機訪問數(shù)據(jù)的權(quán)限,也可以如下操作 GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
引用 另外,當用客戶端連接 mysql 時,發(fā)現(xiàn)無法連接,看來需要對用戶進行重新授權(quán)。操作如下: [root@cicro108 mysql]# bin/mysql -uroot -p -h 127.0.0.1 -A cws3 Enter password: Welcome to the MySQL monitor. Commands end with or /g. Your MySQL connection id is 1863 to server version: 4.1.20-standard Type 'help;' or '/h' for help. Type '/c' to clear the buffer. mysql> grant ALL PRIVILEGES ON *.* to root@"%" identified by "mysql" ; Query OK, 0 rows affected (0.17 sec) 發(fā)現(xiàn)這樣更改權(quán)限以后,遠程仍然不能連接,但是用下面的操作就可以了。 mysql> grant ALL PRIVILEGES ON *.* to root@"%" identified by "mysql" WITH GRANT OPTION; Query OK, 0 rows affected (0.17 sec) 此刻, root 可以被遠程連接,當然這里建立其他非 root 用戶也可以遠程連接。
方案二: MySQL 1130錯誤解決方法: 通過MySQL-Front或MySQL administrator連接MySQL的時候發(fā)生的這個錯誤 ERROR 1130: Host ***.***.***.*** is not allowed to connect to this MySQL server 說明所連接的用戶帳號沒有遠程連接的權(quán)限,只能在本機(localhost)登錄。 需更改 MySQL 數(shù)據(jù)庫里的 user表里的 host項 把localhost改稱%
具體步驟:登陸到MySQL 首先 use MySQL; 按照別人提供的方式update的時候,出現(xiàn)錯誤。 MySQL> update user set host='%' where user = 'root'; ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 然后查看了下數(shù)據(jù)庫的host信息如下: MySQL> select host from user where user = 'root'; +-----------------------+ | host | +-----------------------+ | % | | 127.0.0.1 | | localhost.localdomain | +-----------------------+ 3 rows in set (0.00 sec) host已經(jīng)有了%這個值,所以直接運行命令: 復(fù)制代碼 代碼如下: MySQL>flush privileges;