標籤:main rtu user 使用者 and clear root state iat
登入mysql伺服器後可使用grant命令來建立使用者並賦予相關許可權。
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP -> ON mysql -> TO [email protected]localhost IDENTIFIED BY ‘password‘;Query OK, 0 rows affected, 1 warning (0.11 sec)
以上命令會在mysql資料庫中的user表建立一條使用者資訊記錄.分號(;)表示指令已完成編輯,準備好執行了。
這時可以通過以下命令來查看建立的使用者是否存在。
mysql> select user,host,authentication_string from user;+------------------+-----------+-------------------------------------------+| user | host | authentication_string |+------------------+-----------+-------------------------------------------+| root | localhost | *74ED8DCE9B1B4B780E427473DDD66F8BE6398E8E || mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE || debian-sys-maint | localhost | *0E2901479C3B89118B95A2622B7F895DFC60C4A0 || zara | localhost | *08F7D6C84224646B57BDF66A6480F337F403F10C || firstuser | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 || rick | localhost | *35EB40C575CD0DAA851919E0E3E28C0718879407 |+------------------+-----------+-------------------------------------------+6 rows in set (0.00 sec)
可見,新使用者已經存在,此時就可以以使用者進行登入了。
注意:在 MySQL5.7 中 user 表的 password項 已換成了authentication_string
mysql> \qByedeamon@deamon-H55M-S2:~$ mysql -u firstuser -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 10Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
3.MYSQL之建立新使用者