安装mysql
bash
sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get install mysql-client
测试mysql
bash
systemctl status mysql.service
配置mysql
bash
//修改密码
sudo mysql -u root -p
set password for 用户名@localhost = password('新密码');
//修改root的host属性使其在任意主机上可以登录
update user set host='%' where user='root' and host='localhost';
//刷新权限
flush privileges
//退出
quit
//修改配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
端口号默认是3306有多个版本的MySQL的话需要修改,正常情况下不需要修改,需要将bind-address注释掉
启动mysql数据库服务
bash
//开启
sudo service mysql start
//重启
sudo service mysql restart
//关闭
sudo service mysql status
//设置开机自启
sudo service mysql enable
//停止开机自启
sudo service mysql disable
最后测试一下连接情况
python
import web
gdb=web.database(
dbn='mysql',
host='192.168.1.7',
port=3306,
user='root',
pw='123456',
db='test'
)
gdb.insert("t", t1=123,)
常见问题:
mysql没有驱动
bash
sudo apt-get update
sudo apt-get upgrade
pip install pymysql
pip install mysqlclient
找不到mysql_config
bash
sudo apt-get install libmysqlclient-dev
pip install mysqlclient