[python] linux安装mysql,设置mysql允许外网访问,并使用sqlalchemy在python中调用

1.linux安装mysql,设置mysql允许外网访问


1.安装
sudo apt install mysql-server

2.设置mysql允许外网访问
  1. 在设定中 /etc/mysql/my.cnf注释掉  bind-address  =127.0.0.1  
2.进入mysql 
>mysql - u root -p ***
  3. 在mysql>下,执行
mysql>  use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;

mysql>  update user set host='%' where user='root';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

3. python中使用需安装

1.sudo apt-get install libmysqld-dev
2.sudo pip3 install mysqlclient




你可能感兴趣的:(python,linux)