Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb

2023-11-02 03:38

本文主要是介绍Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前几天一直在弄这个。本来根据官网的教程一步一步下来之后mysql是可以的,但是在安装了Python-MySQLdb之后发现mysql就不行了,已启动就会出现“The MySQL server quit without updating the PID file(/usr/local/bin/mysql/data/XXXXX.pid"错误或者出现”MySQL server cannot be found(/usr/bin/mysqld_safe)“错误。

   后来发现是一个/etc/mysql/my.cnf这个文件导致的,这个文件是安装了Python-MySQLdb之后才会出现的,除非你安装mysql是把my-default.cnf拷贝到这个位置了。安装好后Python-MySQLdb之后的/etc/mysql/my.cnf文件的内容应该如下:


#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port        = 3306
socket        = /var/run/mysqld/mysqld.sock# Here is entries for some specific programs
# The following values assume you have at least 32M ram# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket        = /var/run/mysqld/mysqld.sock
nice        = 0[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket        = /var/run/mysqld/mysqld.sock
port        = 3306
basedir        = /usr
datadir        = /var/lib/mysql
tmpdir        = /tmp
lc-messages-dir    = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer        = 16M
max_allowed_packet    = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit    = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries    = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id        = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size         = 100M
#binlog_do_db        = include_database_name
#binlog_ignore_db    = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem[mysqldump]
quick
quote-names
max_allowed_packet    = 16M[mysql]
#no-auto-rehash    # faster start of mysql but no tab completition[isamchk]
key_buffer        = 16M#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/



 至于如何修改以上文件从而让mysql正常启动?接下来从我安装mysql和python-MySQLdb的过程说起。当然如果你选择了使用apt-get install python-mysqldb mysql-server是不会出现上述错误的。

一、MySQL源码安装

在这这里我提供自动化脚本以参考,该脚本已经过我在ubuntu12.04下测试:

export SRCDIR="/home/XXXXX" #自己定义
export INSTALLDIR="/usr/local/bin"#自己定义
cd $SRCDIR
apt-get install -y g++ gcc make libpcre3 zlib1g libbz2-dev automake cmake perl libncurses5-dev bison #安装依赖
wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.12.tar.gz #下载源代码
#创建mysql用户及用户组
groupadd mysql
useradd -g mysql mysql
#创建mysql的安装目录以及数据库数据存放目录
mkdir -p $INSTALLDIR/mysql
mkdir -p $INSTALLDIR/mysql/data
#安装mysql
tar -zxvf mysql-5.6.12.tar.gz
cd mysql-5.6.12
cmake . -DCMAKE_INSTALL_PREFIX=$INSTALLDIR/mysql -DMYSQL_DATADIR=$INSTALLDIR/mysql/data  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make
make install
#设置目录权限
cd $INSTALLDIR/mysql
chown -R root:mysql . #把当前目录中所有文件的所有者所有者设为root,所属组为mysql
chown -R mysql:mysql data
#将配置拷贝到全局目录下
cp support-files/my-default.cnf /etc/my.cnf
#创建系统数据库的表
#scripts/mysql_install_db --user=mysql
scripts/mysql_install_db --user=mysql --basedir=$INSTALLDIR/mysql --datadir=$INSTALLDIR/mysql/data
#设置环境变量
cat > /root/export.sh << EOF
export PATH=$PATH:$INSTALLDIR/mysql/bin:$INSTALLDIR/mysql/lib
EOF
echo 'source /root/export.sh' >> /root/.bashrc
source /root/export.sh#将mysql的启动服务添加到系统服务中cp /usr/local/bin/mysql/support-files/mysql.server /etc/init.d/mysql/etc/init.d/mysql start
#修改MySQL的root用户的密码以及打开远程连接
mysql -u root mysql
use mysql;
desc user;
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
update user set Password = password(‘your mysql password’) where User='root';
select Host,User,Password from user where User='root';
flush privileges;
exit
/etc/init.d/mysql stop



cmake编译参数说明:

-DCMAKE_INSTALL_PREFIX //安装目录

-DINSTALL_DATADIR //数据库存放目录

-DDEFAULT_CHARSET=utf8  //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci//校验字符

-DEXTRA_CHARSETS=all   //安装所有扩展字符集

-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据

注意事项:

重新编译时,需要清除旧的对象文件和缓存信息。

#make clean

# rm-f CMakeCache.txt

# rm-rf /etc/my.cnf

至此,mysql是可以正常运作的。接下来我们安装Python-MySQLdb。

二、Python-MySQLdb源码安装

如自动化脚本所示:

cd $SRCDIR
apt-get install -y python-dev libmysqld-dev
wget http://nchc.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
tar -zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
sed -i -e "s/#mysql_config = \/usr\/local\/bin\/mysql_config/mysql_config=\/usr\/local\/bin\/mysql\/bin\/mysql_config/g" ./site.cfg
python setup.py build
python setup.py install
ln -s $INSTALLDIR/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18



如果此时启动mysql,则会出现文章开始时所出现的错误。这些错误是由于/etc/mysql/my.cnf中的配置选项不匹配有关的。

接下来,我们需要对该文件作出一些修改,即可使mysql正常启动,脚本如下所示:

cat > /etc/mysql/my.cnf << EOF
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket    = /var/run/mysqld/mysqld.sock
port = 3306
basedir = $INSTALLDIR/mysql
datadir = $INSTALLDIR/mysql/data
tmpdir    = /tmp
lc-messages-dir    = $INSTALLDIR/mysql/share
skip-external-locking
skip-name-resolve
bind-address = 0.0.0.0
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error =$INSTALLDIR/mysql/data/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M[mysqldump]
quick
quote-names
max_allowed_packet = 16M[mysql][isamchk]
key_buffer = 16M#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
EOF



此时即可正常启动mysql。


这篇关于Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/327831

相关文章

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

Centos7安装Mongodb4

1、下载源码包 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz 2、解压 放到 /usr/local/ 目录下 tar -zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgzmv mongodb-linux-x86_64-rhel70-4.2.1/

python: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

Centos7安装JDK1.8保姆版

工欲善其事,必先利其器。这句话同样适用于学习Java编程。在开始Java的学习旅程之前,我们必须首先配置好适合的开发环境。 通过事先准备好这些工具和配置,我们可以避免在学习过程中遇到因环境问题导致的代码异常或错误。一个稳定、高效的开发环境能够让我们更加专注于代码的学习和编写,提升学习效率,减少不必要的困扰和挫折感。因此,在学习Java之初,投入一些时间和精力来配置好开发环境是非常值得的。这将为我

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

安装nodejs环境

本文介绍了如何通过nvm(NodeVersionManager)安装和管理Node.js及npm的不同版本,包括下载安装脚本、检查版本并安装特定版本的方法。 1、安装nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash 2、查看nvm版本 nvm --version 3、安装

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能