最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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';

補充: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í)行,又報錯!
反復確認很多遍執(zhí)行,又又報錯!

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

版本的不同導致

首先,你先檢查一下你的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;

成功。

細心的朋友有沒有注意到返回結(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í)行grant呢?

先創(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)棄用了。

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

相關文章

最新評論

康定县| 洛南县| 新疆| 洪湖市| 麻城市| 大邑县| 威信县| 喜德县| 柳河县| 荆门市| 东城区| 禹州市| 馆陶县| 寿宁县| 五家渠市| 贡山| 仁化县| 武乡县| 武川县| 桐庐县| 昌乐县| 大埔县| 宜君县| 崇仁县| 察隅县| 曲松县| 绥德县| 新平| 彰武县| 威宁| 南投县| 吉林省| 乐清市| 长武县| 广宗县| 玉树县| 巩义市| 禄丰县| 乌拉特中旗| 波密县| 金溪县|