pythonmysql源码安装_源码包安装(Pythonmysqlredis)3.1解压及制作软连接
tar xf mysql-5.7.20-linux-glibc2.12-x86_
ln-s mysql-5.7.20-linux-glibc2.12-x86_64 mysql3.2编辑环境变量
在根⽬录'/'下的etc⽂件
vim/etc/profile
在⽂件最后⼀⾏,添加以下⼀⾏:
export PATH=/opt/mysql/bin:$PATH⽣效配置:
source/etc/profile3.3卸载centos⾃带mariadb
yum remove mariadb-libs3.4 ⽣成配置⽂件(/etc/myf)
vim/etc/myf
---------------------------------
[mysqld]
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
user=mysql
log_error=/var/log/mysql.log
log_bin=/opt/mysql/data/mysql-bin
server_id=100[mysql]
socket=/tmp/mysql.sock
----------------------------------3.5创建⽤户和数据⽬录,并授权
1.创建⼀个⽤户
useradd mysql
mkdir/opt/mysql/data
2.授权
sql /opt/mysql3.6初始化数据
[root@python3 ~]#mysqld --initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql
2019-01-04T03:58:03.128958Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2019-01-04T03:58:03.142436Z 0 [ERROR] Could not open file '/var/log/mysql.log' forerror logging: Permission denied2019-01-04T03:58:03.142492Z 0[ERROR] Aborting
报错解决:
touch/var/log/mysql.log
给权限:
sql /var/log/mysql.log
再次初始化:
mysqld--initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql3.7启动mysql,切换到启动⽂件所在的⽂件夹
cd/opt/mysql/support-files
执⾏下⾯命令启动mysql
./mysql.server start
为了启动⽅便将启动⽂件拷贝到/etc下的配置⽂件
cp mysql.server/etc/init.d/mysqld
启动mysql⽤start,restart都可以/etc/init.d/mysqld restart
扩展:使⽤systemctl 管理mysql,写⼊下⾯⽂件就可以⽤systemctl来启动mysql
vim/etc/systemd/system/mysqld.service
-----------------------------------------------------------------
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/myf
LimitNOFILE= 5000-------------------------------------------------------------------------------
启动mysql
systemctl restart mysqld
关闭mysql
systemctl stop mysql
查看mysql的端⼝
netstat-tulnp |grep 3306
查看mysql软件是否启动
netstat -lnp | grep mysql
如果修改配置⽂件需要:
systemctl daemon-reload
3.8测试python3链接mysql
创建mysql链接⽤户
授权⽤户
grant all on*.* to root@'10.0.0.%' identified by '123';
create database bbs charset utf8;
python代码测试:
更新pip
pip3 install--upgrade pip
mysql下载libs包的网址安装python连接包
pip3 install pymysql
测试脚本
vim testmysql.py
----------------------------------------------------------#!/usr/bin/python3import pymysql db= t("10.0.0.100","root","123","bbs")
data=cursor.fetchone()
print ("Database version : %s" %data)
db.close()
----------------------------------------------------------
python3 testmysql.py

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。