如果您最近使用MySQL創(chuàng)建了新用戶,但是無(wú)法登錄,那么您可能會(huì)遇到以下問(wèn)題之一:
1. 用戶密碼已過(guò)期
mysql>SELECT User,Password,Password_Expire FROM mysql.user; +--------+-------------------------------------------+-----------------------------+ | User | Password | Password_Expire | +--------+-------------------------------------------+-----------------------------+ | root | *14E65567D9CABF7CFE79D6C48F238F09D276C3BB | 2022-08-27 14:20:10.000000 | | user1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 2022-08-27 14:20:10.000000 | +--------+-------------------------------------------+-----------------------------+ 2 rows in set (0.00 sec)
如上所示,可以檢查密碼過(guò)期的日期。如果過(guò)期,用戶將不允許登錄并且必須更改密碼。您可以通過(guò)以下命令更改用戶密碼:
mysql>ALTER USER 'user1'@'localhost' IDENTIFIED BY '{new_password}';
2. 用戶主機(jī)不正確
mysql>SELECT User, Host FROM mysql.user; +--------+-----------+ | User | Host | +--------+-----------+ | root | % | | user1 | localhost | +--------+-----------+ 2 rows in set (0.00 sec)
如上所示,您可以檢查用戶的主機(jī)是否正確。在上面的示例中,user1只允許在本地主機(jī)上登錄。如果您試圖從其他主機(jī)登錄,您將無(wú)法成功。
3. 用戶沒有足夠的權(quán)限
mysql>SHOW GRANTS FOR 'user1'@'localhost'; +---------------------------------------------------------------------------------------------------------+ | Grants for user1@localhost | +---------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'user1'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' | | GRANT ALL PRIVILEGES ON `test`.* TO 'user1'@'localhost' | +---------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
如上所示,您可以檢查是否授予了足夠的權(quán)限。在上面的示例中,user1僅授予了對(duì)test數(shù)據(jù)庫(kù)的所有特權(quán)。如果您試圖訪問(wèn)其他數(shù)據(jù)庫(kù)或表,您將無(wú)法成功。
以上是一些可能會(huì)導(dǎo)致MySQL新用戶無(wú)法登錄的常見問(wèn)題和解決方案。通過(guò)檢查上述內(nèi)容,您可以嘗試使新用戶能夠成功登錄并執(zhí)行所需的操作。