亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

MySQL在grant時報錯ERROR?1064?(42000)的原因及解決方法

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

網(wǎng)上查到的grant方式大多會報錯,主要原因是MySQL版本8.0后不能再使用原來的方式

查詢MySQL版本

SELECT version();

在8.0版本下

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

正確的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總是報錯,怎么回事?

用過MySQL的朋友都知道,經(jīng)常會有一些grant(授權(quá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í)行,報錯!
每個字母敲后執(zhí)行,又報錯!
反復(fù)確認(rèn)很多遍執(zhí)行,又又報錯!

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

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

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

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

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

報錯了

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ì)心的朋友有沒有注意到返回結(jié)果里有一個信息: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)

原來在MySQL5.7的時候,官方就提示了,這個語法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)

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

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

相關(guān)文章

最新評論