1、cmd---pip3 install PyMySQL
2、>>>import pymysql
3、mysql>create database bookdb character set utf8;
4、>>>conn=pymysql.connect(host='localhost',port=3306,user='gao',passwd='123456',db='bookdb',charset='utf8')
5、>>>cur=conn.cursor()
6、>>>cur.executemany("insert into users(username,password,email) values(%s,%s,%s)",(("python","1234","py@python.com"),("python2","12345","py2@python.com"),("python3","12346","py3@python.com"),("python4","12347","py4@python.com")))
7、>>>conn.commit()
允许从任何主机连接到mysql服务器:
(创建一个表所有用户都可以看见并操作,只要给特定用户授权)
先建一个用户,然后对用户授权远程访问
https://blog.csdn.net/weixin_40079336/article/details/81395590
#先创建一个用户
create user 'gao'@'%' identified by '123123';
#再进行授权
grant all privileges on *.* to 'gao'@'%' with grant option;