欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL在grant時(shí)報(bào)錯(cuò)ERROR?1064?(42000)的原因及解決方法

 更新時(shí)間:2022年08月26日 11:31:48   作者:umichan  
網(wǎng)上查到的grant方式大多會(huì)報(bào)錯(cuò),主要原因是MySQL版本8.0后不能再使用原來(lái)的方式,這篇文章主要介紹了MySQL在grant時(shí)報(bào)錯(cuò)ERROR?1064?(42000),需要的朋友可以參考下

網(wǎng)上查到的grant方式大多會(huì)報(bào)錯(cuò),主要原因是MySQL版本8.0后不能再使用原來(lái)的方式

查詢MySQL版本

SELECT version();

在8.0版本下

grant all privileges on test.* to test@'%' identified by '123456'; 

報(bào)錯(cuò)

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 'identified by '123456'' at line 1

正確的grant方式

create user test@'localhost' identified by '123456';
grant all privileges on test.* to test@'localhost';
flush privileges;

MySQL8.0密碼登錄不上

alter user test@'localhost' identified with mysql_native_password by '123456';

補(bǔ)充:MySQL ERROR 1064 (42000)——不管怎樣grant總是報(bào)錯(cuò),怎么回事?

用過(guò)MySQL的朋友都知道,經(jīng)常會(huì)有一些grant(授權(quán))操作,不知道你有沒(méi)有遇到過(guò)這樣的問(wèn)題。

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 ‘identified by ‘123456’’ at line 1

MySQL grant的SQL

粘貼到終端執(zhí)行,報(bào)錯(cuò)!
每個(gè)字母敲后執(zhí)行,又報(bào)錯(cuò)!
反復(fù)確認(rèn)很多遍執(zhí)行,又又報(bào)錯(cuò)!

都要瘋了,怎么辦。別急,接著看文章。

版本的不同導(dǎo)致

首先,你先檢查一下你的MySQL版本, 大多數(shù)執(zhí)行報(bào)錯(cuò)的MySQL版本是8.0的,通過(guò)記憶甚至盲打命令都不層報(bào)錯(cuò)的,估計(jì)通常都是用的最多的5.7了。信不信呢?

用真實(shí)數(shù)據(jù)測(cè)試

1.先用MySQL 8.0試一下

mysql> grant all privileges on test.* to test@'%' identified by '123456';  
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 'identified by '123456'' at line 1

報(bào)錯(cuò)了

2.再用MySQL 5.7試一下

mysql> grant all privileges on test.* to test@'%' identified by '123456';    
Query OK, 0 rows affected, 1 warning (0.08 sec)
mysql> flush privileges;

成功。

細(xì)心的朋友有沒(méi)有注意到返回結(jié)果里有一個(gè)信息:1 warning,是什么內(nèi)容呢?

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                            |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | Using GRANT for creating new user is deprecated and will be removed in future release. Create new user with CREATE USER statement. |
+---------+------+------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

原來(lái)在MySQL5.7的時(shí)候,官方就提示了,這個(gè)語(yǔ)法SQL將要被棄用了。

正確的執(zhí)行賦權(quán)

那么在MySQL8.0版本及以后,我們?nèi)绾握_執(zhí)行g(shù)rant呢?

先創(chuàng)建用戶,再賦予授權(quán)。

mysql> create user test@'localhost' identified by '123456';
Query OK, 0 rows affected (0.10 sec)

mysql> grant all privileges on test.* to test@'localhost';
Query OK, 0 rows affected (0.17 sec)

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

這個(gè)方法也適用MySQL5.7版本,所以建議大家以后使用這種方式賦權(quán),一鍵建用戶加賦權(quán)官方已經(jīng)棄用了。

到此這篇關(guān)于MySQL在grant時(shí)報(bào)錯(cuò)ERROR 1064 (42000)的文章就介紹到這了,更多相關(guān)mysql  grant報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論