源码包安装(Python mysql redis)

Posted zhaijihai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码包安装(Python mysql redis)相关的知识,希望对你有一定的参考价值。

一  源码包安装

(1)python3.6源码包安装
    ./configure       ------> 定制功能
     make
     make install
     
mysql 源码包
    cmake
    make 
    make install
  
(2) redis 源码包安装 
    make

修改环境变量
vim /etc/profile

添加以下一行:
export PATH=/opt/redis-3.2.10/src:$PATH

生效配置
source /etc/profile


(3) 让python链接redis

unzip redis-py-master.zip 
cd redis-py-master
python3 setup.py install


对redis的单实例进行连接操作
python3
>>>import redis
>>>r = redis.StrictRedis(host=‘localhost‘, port=6379)
>>>r.set(‘name‘, ‘oldguo‘)
True
>>>r.get(‘name‘)
‘oldguo‘

二  经典互联网架构项目

三  二进制包mysql(mysql5.7.20)

3.1 解压及制作软连接
tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql

3.2 编辑环境变量
vim  /etc/profile
添加以下一行:
export PATH=/opt/mysql/bin:$PATH

生效配置:
source /etc/profile

3.3 卸载自带mariadb
yum remove mariadb-libs

3.4 生成配置文件(/etc/my.cnf)
vim /etc/my.cnf
[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 创建用户和数据目录,并授权
useradd mysql 
mkdir  /opt/mysql/data 
chown -R mysql.mysql /opt/mysql


3.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 for more details).
2019-01-04T03:58:03.142436Z 0 [ERROR] Could not open file ‘/var/log/mysql.log‘ for error logging: Permission denied
2019-01-04T03:58:03.142492Z 0 [ERROR] Aborting

报错解决:
touch /var/log/mysql.log 
chown -R mysql.mysql /var/log/mysql.log


再次初始化:
mysqld --initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql


3.7 启动mysql 
cd /opt/mysql/support-files
./mysql.server start

cp mysql.server /etc/init.d/mysqld

/etc/init.d/mysqld restart


扩展:使用systemctl 管理mysql
vim /etc/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000


systemctl restart mysqld

netstat -tulnp |grep 3306


3.8 测试python3链接mysql

创建mysql链接用户

grant all on *.* to [email protected]‘10.0.0.%‘ identified by ‘123‘;
create database bbs charset utf8;

python代码测试:

pip3 install --upgrade pip
pip3 install pymysql

vim testmysql.py
#!/usr/bin/python3
import pymysql
db = pymysql.connect("10.0.0.100","root","123","bbs" )
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print ("Database version : %s " % data)
db.close()

python3  testmysql.py 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

以上是关于源码包安装(Python mysql redis)的主要内容,如果未能解决你的问题,请参考以下文章

源码包安装MySQL

搭建Django链接MySQL流程(python2版)

mysql源码包安装方法

mysql5.7源码安装

如何在centos安装python-mysql

mysql 源码包安装