MySql 8.0.19 權限分配
問題一:You have an error in your SQL syntax —語法問題
MySql8.0.19 版本分配權限這有了一些改變,不需要後面的identified by '123456a'
了
mysql> grant all privileges on sonar_scan.* to 'sonar'@'%' identified by '123456
a';
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 'ident
ified by '123456a'' at line 1
分配權限
mysql> grant all privileges on sonar_scan.* to 'sonar'@'%';
Query OK, 0 rows affected (0.24 sec)
問題二:You are not allowed to create a user with GRANT —權限問題
分配權限,% 代表全域,如果要遠程使用數據庫的話必須分配這個權限。
mysql> grant all privileges on sonar_scan.* to 'sonar'@'%';
Query OK, 0 rows affected (0.24 sec)
如果分配了全域,這個時候再分配本地就會報錯,其實 % 已經包含 localhost 了。
mysql> grant all privileges on sonar_scan.* to 'sonar'@'localhost';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
如果硬要是分配本地的話,要執這麼一句就好了。要換回全域,在把 host 改成 % 就好了。
mysql> update user set host='localhost' where user='sonar';
Query OK, 1 row affected (0.53 sec)
Rows matched: 1 Changed: 1 Warnings: 0
問題三:No database selected —沒選擇數據庫
用一句 use mysql 就能解決問題了。
mysql> update user set host='localhost' where user='sonar';
ERROR 1046 (3D000): No database selected
mysql> use mysql;
Database changed
mysql> update user set host='localhost' where user='sonar';
Query OK, 1 row affected (0.53 sec)
Rows matched: 1 Changed: 1 Warnings: 0
創建數據庫分配權限演示
創建數據庫
mysql> create database sonar_scan default character set utf8 collate utf8_genera
l_ci;
Query OK, 1 row affected, 2 warnings (0.19 sec)
創建用戶
mysql> create user 'sonar' identified by '123456a';
Query OK, 0 rows affected (0.11 sec)
分配權限
mysql> grant all privileges on sonar_scan.* to 'sonar'@'%';
Query OK, 0 rows affected (0.24 sec)
喜歡的點個贊❤吧!