MySQL增加訪問ip

2022-08-26 01:39:10 字數 1381 閱讀 9707

當使用python的pymysql訪問時,如下

import

pymysql

db=pymysql.connect("ip

","root

","passwd

","database-name")

cursor =db.cursor()

cursor.execute(

"select version()")

data =cursor.fetchone()

print("

database version : %s

" %data)

db.close()

會報錯raise errorclass(errno, errval)

pymysql.err.operationalerror: (1130, "10.197.193.23' is not allowed to connect to this mariadb server")

因為centos裡面的mysql預設只能本機訪問(localhost),需要進入mysql資料(或者maiadb),新增如下指令,來開通所有ip訪問

mysql>grantallprivilegeson*.*to'root'@'%'identifiedby'123456'withgrantoption;

mysql>flushprivileges;

下面一種是開通個別開別,例如

mysql>grant all on *.* to root@'10.60.160.%' identified by '123465'; flush privileges;

mysql>flushprivileges;

mysql>flushprivileges;

下面一種是開通個別開別,例如

mysql>grant all on *.* to root@'10.60.160.%' identified by '123465'; flush privileges;

mysql>flushprivileges;

mysql 遠端 ip訪問

預設情況下linux內的mysql資料庫mysql,user表內的使用者許可權只是對localhost即本機才能登陸。需要更改許可權 如下的方式確認 root mysql h localhost u mysql p enter password welcome to the mysql monito...

mysql允許遠端IP訪問

預設情況下linux內的mysql資料庫mysql,user表內的使用者許可權只是對localhost即本機才能登陸。需要更改許可權 mysql grant all privileges on to root identified by password with grant option 表示是所...

mysql允許外部IP訪問

預設情況下linux內的mysql資料庫mysql,user表內的使用者許可權只是對localhost即本機才能登陸。需要更改許可權 mysql grant all privileges on to root identified by password with grant option 表示是所...