[英]mysql connector error 1130: host not allowed to connect to this MySQL server
[英]Host is not allowed to connect to this MySQL server (from VM)
我正在嘗試從VirtualBoxVM中運行的虛擬Raspberry PI連接到mysql。
使用Python腳本:
import mysql.connector
mydb = mysql.connector.connect(
host="MBP",
user="PI-2",
passwd="",
database="temperatureData"
)
mycursor = mydb.cursor()
sql = "INSERT INTO temperature (date, temp_celsius, temp_farenheit)
VALUES (%s, %s, %s)"
val = ("2019-01-14", "20")
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
但是失敗並顯示錯誤:
1130: Host 'MBP' is not allowed to connect to this MySQL server
在Mysql(在Macbook上)中,我通過以下方式設置了用戶:
CREATE USER 'PI-2'@'127.0.0.1' IDENTIFIED BY 'PI-2';
GRANT ALL PRIVILEGES ON *.* TO 'PI-2'@'127.0.0.1' WITH GRANT OPTION;
(由於我在VM內使用NAT,因此使用127.0.0.1-如此處所述: 如何獲取在本地計算機上運行的虛擬盒的ipaddress )
my.cnf文件:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
# bind-address = 127.0.0.1
bind-address = 0.0.0.0
更新:
MBP上ifconfig
輸出:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
[ ... ]
在VM上:
eth0 Link encap:Ethernet HWaddr 08:00:27:41:cb:b4
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::ef2d:bd28:6834:9191/64 Scope:Link
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
使用以下命令授予特權: GRANT ALL PRIVILEGES ON *.* TO 'PI-2'@'MBP' WITH GRANT OPTION;
它允許MySQL接受來自名為MBP的主機的連接。
https://dev.mysql.com/doc/refman/5.6/en/grant.html#grant-accounts-passwords
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.