日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

MySQL笔记 - 用户管理

發(fā)布時(shí)間:2023/12/3 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL笔记 - 用户管理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自:?https://segmentfault.com/a/1190000014856560


MySQL筆記 - 用戶管理

tags: 數(shù)據(jù)庫(kù) MySQL 用戶管理


學(xué)習(xí)目標(biāo)

MySQL是一個(gè)多用戶數(shù)據(jù)庫(kù),具有功能強(qiáng)大的訪問(wèn)控制系統(tǒng),可以為不同用戶指定允許的權(quán)限。

MySQL用戶可以分為普通用戶和root用戶。root用戶是超級(jí)管理員,擁有所有權(quán)限,包括創(chuàng)建用戶、刪除用戶和修改用戶的密碼等管理權(quán)限;普通用戶只有被授予的各種權(quán)限。

用戶管理包括管理用戶賬戶、權(quán)限等。


1. 權(quán)限表

MySQL服務(wù)器通過(guò)權(quán)限表來(lái)控制用戶對(duì)數(shù)據(jù)庫(kù)的訪問(wèn),權(quán)限表存放在MySQL數(shù)據(jù)庫(kù)中,由MySQL_install_db腳本初始化。

存儲(chǔ)賬戶權(quán)限信息表主要有:user、host、db、tables_priv、columns_priv、procs_priv。本節(jié)主要介紹這些表的內(nèi)容和作用。


1.1 user表

user表是MySQL中最重要的一個(gè)權(quán)限表,記錄允許連接到服務(wù)器的賬號(hào)信息,這里的權(quán)限是全局的。

執(zhí)行mysql> describe mysql.user;命令得到如下顯示表信息:

FieldTypeNullKeyDefaultExtra
Hostchar(60)NOPRI??
Userchar(32)NOPRI??
Select_privenum('N','Y')NO?N?
Insert_privenum('N','Y')NO?N?
Update_privenum('N','Y')NO?N?
Delete_privenum('N','Y')NO?N?
Create_privenum('N','Y')NO?N?
Drop_privenum('N','Y')NO?N?
Reload_privenum('N','Y')NO?N?
Shutdown_privenum('N','Y')NO?N?
Process_privenum('N','Y')NO?N?
File_privenum('N','Y')NO?N?
Grant_privenum('N','Y')NO?N?
References_privenum('N','Y')NO?N?
Index_privenum('N','Y')NO?N?
Alter_privenum('N','Y')NO?N?
Show_db_privenum('N','Y')NO?N?
Super_privenum('N','Y')NO?N?
Create_tmp_table_privenum('N','Y')NO?N?
Lock_tables_privenum('N','Y')NO?N?
Execute_privenum('N','Y')NO?N?
Repl_slave_privenum('N','Y')NO?N?
Repl_client_privenum('N','Y')NO?N?
Create_view_privenum('N','Y')NO?N?
Show_view_privenum('N','Y')NO?N?
Create_routine_privenum('N','Y')NO?N?
Alter_routine_privenum('N','Y')NO?N?
Create_user_privenum('N','Y')NO?N?
Event_privenum('N','Y')NO?N?
Trigger_privenum('N','Y')NO?N?
Create_tablespace_privenum('N','Y')NO?N?
ssl_typeenum('','ANY',
'X509','SPECIFIED')
NO???
ssl_cipherblobNO?NULL?
x509_issuerblobNO?NULL?
x509_subjectblobNO?NULL?
max_questionsint(11) unsignedNO?0?
max_updatesint(11) unsignedNO?0?
max_connectionsint(11) unsignedNO?0?
max_user_connectionsint(11) unsignedNO?0?
pluginchar(64)NO?mysql_native_password?
authentication_stringtextYES?NULL?
password_expiredenum('N','Y')NO?N?
password_last_changedtimestampYES?NULL?
password_lifetimesmallint(5) unsignedYES?NULL?
account_lockedenum('N','Y')NO?N?

45 rows in set (0.00 sec)

字段說(shuō)明:

  • 用戶列
    user表的用戶信息列包括Host、User、authentication_string,其中Host和User為表的聯(lián)合主鍵。authentication_sting為用戶密碼的哈希值。當(dāng)一個(gè)用戶連接時(shí),只有這3個(gè)值完全匹配才被允許。
  • 權(quán)限列
    后面帶_pri的都是用戶權(quán)限字段,包括了增、刪、改、查等普通權(quán)限,還包括了關(guān)閉服務(wù)器、加載用戶等高級(jí)權(quán)限。普通權(quán)限用于對(duì)數(shù)據(jù)庫(kù)實(shí)施操作行為的限制;高級(jí)權(quán)限用于數(shù)據(jù)庫(kù)管理行為。

    user表中對(duì)應(yīng)的權(quán)限是針對(duì)所有用戶數(shù)據(jù)數(shù)據(jù)庫(kù)的。這些字段值的類型為ENUM,可以取值只能為Y和N。修改權(quán)限使用grant語(yǔ)句和update語(yǔ)句。

  • 安全列
    安全列只有6個(gè)字段,其中兩個(gè)是ssl相關(guān),兩個(gè)是x509相關(guān),另外兩個(gè)是授權(quán)插件相關(guān)。
  • 資源控制列

    • max_questions?- 用戶每小時(shí)允許執(zhí)行的查詢操作次數(shù)。
    • max_updates?- 用戶每小時(shí)允許執(zhí)行的更新操作次數(shù)。
    • max_connections?- 用戶每小時(shí)允許執(zhí)行的連接操作次數(shù)。
    • max_user_connections?- 用戶允許同時(shí)建立的連接次數(shù)。

  • 1.2 db表和host表

    db表和host表是MySQL數(shù)據(jù)中非常重要的權(quán)限表。db表中存儲(chǔ)了用戶對(duì)某個(gè)數(shù)據(jù)庫(kù)的操作權(quán)限,決定用戶能從哪個(gè)主機(jī)存取那個(gè)數(shù)據(jù)庫(kù)。

    執(zhí)行mysql> describe mysql.db;后顯示結(jié)果如下:

    FieldTypeNullKeyDefaultExtra
    Hostchar(60)NOPRI??
    Dbchar(64)NOPRI??
    Userchar(32)NOPRI??
    Select_privenum('N','Y')NO?N?
    Insert_privenum('N','Y')NO?N?
    Update_privenum('N','Y')NO?N?
    Delete_privenum('N','Y')NO?N?
    Create_privenum('N','Y')NO?N?
    Drop_privenum('N','Y')NO?N?
    Grant_privenum('N','Y')NO?N?
    References_privenum('N','Y')NO?N?
    Index_privenum('N','Y')NO?N?
    Alter_privenum('N','Y')NO?N?
    Create_tmp_table_privenum('N','Y')NO?N?
    Lock_tables_privenum('N','Y')NO?N?
    Create_view_privenum('N','Y')NO?N?
    Show_view_privenum('N','Y')NO?N?
    Create_routine_privenum('N','Y')NO?N?
    Alter_routine_privenum('N','Y')NO?N?
    Execute_privenum('N','Y')NO?N?
    Event_privenum('N','Y')NO?N?
    Trigger_privenum('N','Y')NO?N?

    22 rows in set (0.04 sec)

    host表中存儲(chǔ)了某個(gè)主機(jī)對(duì)數(shù)據(jù)庫(kù)的操作權(quán)限,配合db權(quán)限表對(duì)給定主機(jī)上的數(shù)據(jù)庫(kù)級(jí)操作權(quán)限做更細(xì)致的控制,這個(gè)表不受grant和revoke語(yǔ)句的影響。此表在“Server version: 5.7.20 MySQL Community Server (GPL)”中并未發(fā)現(xiàn)。


    1.3 tables_priv表和columns_priv表

    這2張表分別對(duì)具體的表和表中的字段來(lái)設(shè)置權(quán)限。

    tables_priv表信息:

    ;mysql> describe mysql.tables_priv;

    FieldTypeNullKeyDefaultExtra
    Hostchar(60)NOPRI??
    Dbchar(64)NOPRI??
    Userchar(32)NOPRI??
    Table_namechar(64)NOPRI??
    Grantorchar(93)NOMUL??
    TimestamptimestampNO?CURRENT_TIMESTAMPon update CURRENT_TIMESTAMP
    Table_privset('Select',
    'Insert',
    'Update',
    'Delete',
    'Create',
    'Drop',
    'Grant',
    'References',
    'Index',
    'Alter',
    'Create View',
    'Show view',
    'Trigger')
    NO???
    Column_privset('Select',
    'Insert',
    'Update',
    'References')
    NO????

    8 rows in set (0.04 sec)

    columns_priv表信息:

    mysql> describe mysql.columns_priv;

    FieldTypeNullKeyDefaultExtra
    Hostchar(60)NOPRI??
    Dbchar(64)NOPRI??
    Userchar(32)NOPRI??
    Table_namechar(64)NOPRI??
    Column_namechar(64)NOPRI??
    TimestamptimestampNO?CURRENT_TIMESTAMPon update CURRENT_TIMESTAMP
    Column_privset('Select',
    'Insert',
    'Update',
    'References')
    NO???

    7 rows in set (0.02 sec)


    1.4 procs_priv表

    procs_priv表可以對(duì)存儲(chǔ)過(guò)程和存儲(chǔ)函數(shù)設(shè)置操作權(quán)限。

    mysql> describe mysql.procs_priv;

    FieldTypeNullKeyDefaultExtra
    Hostchar(60)NOPRI??
    Dbchar(64)NOPRI??
    Userchar(32)NOPRI??
    Routine_namechar(64)NOPRI??
    Routine_typeenum(
    'FUNCTION',
    'PROCEDURE')
    NOPRINULL?
    Grantorchar(93)NOMUL??
    Proc_privset('Execute',
    'Alter Routine',
    'Grant')
    NO???
    TimestamptimestampNO?CURRENT_TIMESTAMPon update CURRENT_TIMESTAMP

    rows in set (0.02 sec)


    2. 賬戶管理

    2.1 登錄和退出MySQL服務(wù)器

    通過(guò)MySQL -help命令可以查看MySQL命令的幫助信息。MySQL命令的常用參數(shù)如下:

    • -h 主機(jī)名:可以指定主機(jī)名稱和IP

    ,如果不指定,默認(rèn)是localhost。

    • -P 端口號(hào):指定服務(wù)器的端口號(hào),默認(rèn)為3306。
    • -u 用戶名:指定用戶名。
    • -p密碼:可以用使用該參數(shù)指定登錄密碼,注意:?密碼與p之間不能有空格。
    • -e "SQL語(yǔ)句":如果指定了該語(yǔ)句,會(huì)在登錄后執(zhí)行SQL語(yǔ)句。
    • '數(shù)據(jù)庫(kù)名稱:可以在命令的最后指定數(shù)據(jù)庫(kù)名稱。

    [例1] 用戶root,密碼為foo,從主機(jī)localhost登錄到MySQL服務(wù)器,設(shè)置test_db數(shù)據(jù)庫(kù)為登錄后的默認(rèn)當(dāng)前數(shù)據(jù)庫(kù)。

    C:\mysql5.7.2\bin>mysql -h localhost -u root -pfoo test_db Enter password: *********Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 5.7.20 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> select database();+------------+ | database() | +------------+ | test_db | +------------+ 1 row in set (0.00 sec)

    [例2] 使用root用戶,密碼為foo,從主機(jī)localhost登錄到MySQL服務(wù)器,設(shè)置缺省數(shù)據(jù)庫(kù)為test_db,并執(zhí)行語(yǔ)句describe test1; select * from test1;。

    C:\mysql5.7.2\bin>mysql -h localhost -u root -pfoo test_db -e "describe test1; select * from test1" mysql: [Warning] Using a password on the command line interface can be insecure.+-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | a1 | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ +------+ | a1 | +------+ | 1 | | 3 | | 4 | +------+

    要退出MySQL服務(wù)器登錄,請(qǐng)使用quit。

    mysql> quit ByeC:\mysql5.7.2>bin>

    2.2 新建普通用戶

    要?jiǎng)?chuàng)建新用戶,必須具有相應(yīng)的權(quán)限來(lái)執(zhí)行創(chuàng)建操作。在MySQL數(shù)據(jù)庫(kù)中,有兩種方式創(chuàng)建新用戶,一種是使用create user或grant語(yǔ)句;另一種是直接操作MySQL授權(quán)表。

    (1). 使用create user語(yǔ)句創(chuàng)建新用戶

    create user語(yǔ)句基本語(yǔ)法格式如下:

    CREATE USER user_specification[, user_specification]...user_specification: user@host [IDENTIFIED BY [PASSWORD] 'password' | IDENTIFIED WITH auth_plugin [AS 'auth_sting']]

    值得注意的是:如果使用PASSWORD關(guān)鍵字,后面的密碼要使用哈希值字符竄,否則'password'使用明文密碼。

    [例3] 使用create user創(chuàng)建一個(gè)用戶,用戶名是jack,密碼是pw,主機(jī)名為localhost,語(yǔ)句如下:

    mysql> create user `jack`@`localhost` identified by 'pw'; Query OK, 0 rows affected (0.24 sec)-- 如果使用password關(guān)鍵字則要如下操作:mysql> select password('pw'); +-------------------------------------------+ | password('pw') | +-------------------------------------------+ | *D821809F681A40A6E379B50D0463EFAE20BDD122 | +-------------------------------------------+ 1 row in set, 1 warning (0.03 sec)mysql> create user jack1@localhost identified by password '*D821809F681A40A6E379B50D0463EFAE20BDD122'; Query OK, 0 rows affected, 1 warning (0.00 sec)

    (2). 使用grant語(yǔ)句創(chuàng)建新用戶

    基本語(yǔ)法如下:

    GRANT privileges ON [object_type] priv_level TO user@host [IDENTIFIED BY 'password'] [, user [IDENTIFIED BY 'password']] [WITH GRANT OPTION]object_type: {TABLE| FUNCTION| PROCEDURE }priv_level: {*| *.*| db_name.*| db_name.tbl_name| tbl_name| db_name.routine_name }

    說(shuō)明:WITH GRANT OPTION子句表示對(duì)新建立的用戶賦予GRANT權(quán)限,即該用戶可以對(duì)其他用戶賦予權(quán)限。

    [例4] 使用grant語(yǔ)句創(chuàng)建兩個(gè)新用戶jack2和jack3,密碼分別為pw1和pw2,并授于他們對(duì)所有數(shù)據(jù)表的select和update權(quán)限。

    mysql> grant select,update on table *.* to jack2@localhost identified by 'pw1', jack3@localhost identified by 'pw2'; Query OK, 0 rows affected, 2 warnings (0.03 sec)mysql> show warnings; LevelCodeMessage
    Warning1287Using GRANT for creating new user is deprecated and will be removed in future release. Create new user with CREATE USER statement.
    Warning1287Using GRANT for creating new user is deprecated and will be removed in future release. Create new user with CREATE USER statement.
    2 rows in set (0.00 sec)-- 查看警告可知,最好不要用grant語(yǔ)句來(lái)添加新用戶,而要用create user語(yǔ)句添加新用戶后再授權(quán)。如下所示,則不會(huì)出現(xiàn)警告:mysql> create user jack4@localhost identified by 'pw3'; Query OK, 0 rows affected (0.00 sec)mysql> grant select, update on table *.* to jack4@localhost; Query OK, 0 rows affected (0.00 sec)

    對(duì)于用戶名到底是使用user@host,還是user呢?請(qǐng)點(diǎn)此進(jìn)一步查看,簡(jiǎn)單來(lái)說(shuō)指定user就是要同時(shí)指定用戶和主機(jī),這兩個(gè)是一體的。

    (3). 直接對(duì)user表進(jìn)行操作

    在MySQL中create user和grant語(yǔ)句都是實(shí)際上都是對(duì)user表進(jìn)行操作,但一般不建議這樣做,除非特殊情況或者極熟悉MySQL的user表中的各項(xiàng)設(shè)置才可以。

    [例5] 使用insert創(chuàng)建一個(gè)新賬戶

    mysql> insert into mysql.user (host,user,authentication_string)-> values('localhost', 'jack5', password('pw'));ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default valuemysql> show warnings; LevelCodeMessage
    Warning1681'PASSWORD' is deprecated and will be removed in a future release.
    Error1364Field 'ssl_cipher' doesn't have a default value
    Error1364Field 'x509_issuer' doesn't have a default value
    Error1364Field 'x509_subject' doesn't have a default value
    4?rows in set (0.01?sec)

    由提示信息可以看出并未添加成功,需要指定多個(gè)相關(guān)字段才能添加成功,所以請(qǐng)使用MySQL提供的標(biāo)準(zhǔn)的語(yǔ)句。


    2.3 刪除普通用戶

    (1). 使用drop user語(yǔ)句刪除用戶

    基本語(yǔ)法:

    drop user user [, user];

    [例6] 刪除用戶jack4@localhost。

    mysql> drop user jack4@localhost; Query OK, 0 rows affected (0.02 sec)

    (2). 直接對(duì)user表進(jìn)行操作

    [例7] 刪除用戶jack3@localhost。

    mysql> delete from mysql.user where user='jack3' and host='localhost'; Query OK, 1 row affected (0.16 sec)

    2.4 root用戶修改自己的密碼

    (1). 使用mysqladmin命令在命令行中修改密碼

    [例8] 將root用戶的密碼修改為"xfoox"

    C:\>mysqladmin -u root -h 192.168.1.33 -pfoo password "xfoox" mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

    說(shuō)明:?-p的密碼foo是緊跟著的,不能有空格;password后面的密碼要使用雙引號(hào);如果省略掉-p后面的密碼會(huì)要求你輸入原密碼。當(dāng)然你可以使用SSL連接服務(wù)器,以增加安全性,MySQL開(kāi)啟SSL安全連接的文章請(qǐng)點(diǎn)此訪問(wèn)

    (2). 使用set password語(yǔ)句修改密碼

    正常登陸服務(wù)器后,使用如下語(yǔ)句修改:

    mysql> set password=password("foo"); Query OK, 0 rows affected (0.14 sec)

    注意:在最新版本的MySQL8.0中并不支持password函數(shù),只需要直接寫(xiě)密碼即可。

    (3). 直接修改user表

    mysql> update mysql.user set password=password("foo") where user = "root" and host = "localhost"; ERROR 1054 (42S22): Unknown column 'password' in 'field list'mysql> update mysql.user set authentication_string=password("foo") where user = "root" and host = "localhost"; Query OK, 0 rows affected, 1 warning (0.15 sec) Rows matched: 1 Changed: 0 Warnings: 1mysql> flush privileges; Query OK, 0 rows affected (0.17 sec)

    注意:一般不要使用這種方法,因?yàn)槊總€(gè)版本的密碼存貯字段名可能不同,最后要記得使用flush privileges語(yǔ)句來(lái)沖洗權(quán)限表,然后才可以使用新密碼登陸。


    2.5 root用戶修改普通用戶的密碼

    (1). 使用set password語(yǔ)句修改

    mysql> set password for jack@localhost = password('foo'); Query OK, 0 rows affected, 1 warning (0.04 sec)mysql> show warnings;| Warning | 1287 | 'SET PASSWORD FOR <user> = PASSWORD('<plaintext_password>')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR <user> = '<plaintext_password>' instead |1 row in set (0.00 sec)

    (2). 使用grant usage語(yǔ)句來(lái)修改

    mysql> grant usage on *.* to jack@localhost identified by 'foo'; Query OK, 0 rows affected, 1 warning (0.12 sec)

    說(shuō)明:警告提示仍然為未來(lái)版本可能不支持該語(yǔ)句來(lái)修改用戶的密碼。

    (3). 直接修改user表

    同root用戶。


    2.6 普通用戶修改自的密碼

    普通用戶正常登陸后,使用如下語(yǔ)句修改:

    mysql> set password = 'foo'; Query OK, 0 rows affected (0.07 sec)

    2.7 root用戶密碼丟失的解決辦法

    基本步驟

  • 越過(guò)權(quán)限表來(lái)啟動(dòng)服務(wù)。(MySQL服務(wù)名字可以自定義的,請(qǐng)按自己的情況處理,一般為mysql
  • 修改密碼。
  • 刷新權(quán)限表。
  • 詳細(xì)步驟演示

  • 打開(kāi)管理員命令窗口,停止本機(jī)的MySQL服務(wù),再用參數(shù)--skip-grant-tables來(lái)越過(guò)權(quán)限表的檢查來(lái)啟動(dòng)服務(wù)。

    注意,此時(shí)光標(biāo)會(huì)不斷閃爍,不要關(guān)閉此窗口。

    如果在MySQL8.0版本中,啟動(dòng)服務(wù)的命令為:E:\mysql8\bin>mysqld --skip-grant-tables --shared-memory --console?,附加--console是為了將信息輸出到控制臺(tái),不然信息會(huì)不顯示。

    E:\mysql8\bin>mysqld --skip-grant-tables --shared-memory --console 2018-05-14T11:53:03.811523Z 0 [System] [MY-010116] [Server] E:\mysql8\bin\mysqld.exe (mysqld 8.0.11) starting as process 4472 2018-05-14T11:53:06.244140Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2018-05-14T11:53:06.320312Z 0 [System] [MY-010931] [Server] E:\mysql8\bin\mysqld.exe: ready for connections. Version: '8.0.11' socket: '' port: 0 MySQL Community Server - GPL. 2018-05-14T11:53:06.455078Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx reported: 'All I/O interfaces are disabled, X Protocol won't be accessible' (注:光標(biāo)會(huì)在這里閃爍) (注:在進(jìn)行完第3步后,在這里我按了Ctrl+c終止,下面是按鍵完畢后的輸出:) 2018-05-14T12:02:51.10644^5CZ 0 [System]E:\mysql8\bin> [MY-013105] [Server] E:\mysql8\bin\mysqld.exe: Normal shutdown. 2018-05-14T12:02:53.120117Z 0 [Warning] [MY-010909] [Server] E:\mysql8\bin\mysqld.exe: Forcing close of thread 9 user: 'root'. 2018-05-14T12:02:54.515625Z 0 [System] [MY-010910] [Server] E:\mysql8\bin\mysqld.exe: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL.
  • 打開(kāi)新的命令窗口,使用root用戶登陸,由于越過(guò)了權(quán)限表,此時(shí)雖然要求輸入密碼,但只需要回車(chē)即可,登錄后修改密碼。

    C:\mysql -u root -p enter password: (此處直接回車(chē)即可)mysql> update mysql.user set authentication_string = password('foo') where user='root' and host='localhost'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 1

    注意:在5.7版本以前的密碼是存儲(chǔ)在password字段里的,以后的版本存儲(chǔ)在authentication_string字段里,并且在MySQL8.0以后,password()函數(shù)也被取消了,采用了caching_sha2_password的加密驗(yàn)證方式,所以,只能把密碼字段先用空白字竄替換,即:authentication_string='',然后重新登陸,因?yàn)槊艽a為空白,所以只需要回車(chē)即可,然后使用alter user root@localhost identified by 'foo';語(yǔ)句來(lái)更改密碼。

  • 刷新權(quán)限

    mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

    最后關(guān)閉管理員窗口,退出登錄,即可重新使用新密碼連接服務(wù)器。

    注意:有時(shí)關(guān)閉了管理員命令窗口,一般MySQL服務(wù)仍然會(huì)在后臺(tái)運(yùn)行,但有時(shí)卻不行。如果不能正常登陸,請(qǐng)查看進(jìn)程,殺掉后,再使用net start mysql啟動(dòng)MySQL服務(wù)即可.(MySQL服務(wù)名字可以自定義的,請(qǐng)按自己的情況處理


  • 總結(jié)

    以上是生活随笔為你收集整理的MySQL笔记 - 用户管理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。