1. 程式人生 > >MySQL client執行過程

MySQL client執行過程

ret 包括 返回結果 user 語義分析 lock line cli exist

由以下示例得出,客戶端連接MySQL時執行語句包括如下過程:
1.認證
是否可以登錄MySQL服務端。
2.語法分析
判斷執行語句是否合法,無語句錯誤。
3.權限分析
判斷執行語句,是否有對目標的相關權限。
4.語義分析
判斷是否存在相應的表和字段
5.優化執行
優化器優化SQL語句後,執行並返回結果。

1)mysql -utest -h127.0.0.1 -p -P3306 -perror
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user ‘test‘@‘127.0.0.1‘ (using password: YES)

mysql> show grants;
+--------------------------------------------------------------------------+
| Grants for [email protected]                                                |
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘test‘@‘127.0.0.1‘ IDENTIFIED BY PASSWORD <secret> |
| GRANT SELECT ON `test`.* TO ‘test‘@‘127.0.0.1‘                           |
+--------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> 
mysql> 
2)
mysql> select *** from test.t;
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 ‘** from test.t‘ at line 1
mysql> 
3)
mysql> select * from a.t;
ERROR 1142 (42000): SELECT command denied to user ‘test‘@‘127.0.0.1‘ for table ‘t‘
mysql> 
mysql> 
4)
mysql> select * from test.t;
ERROR 1146 (42S02): Table ‘test.t‘ doesn‘t exist
mysql> 
mysql> 

MySQL client執行過程