博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb
阅读量:4027 次
发布时间:2019-05-24

本文共 7433 字,大约阅读时间需要 24 分钟。

   前几天一直在弄这个。本来根据官网的教程一步一步下来之后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        = 3306socket        = /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.socknice        = 0[mysqld]## * Basic Settings#user        = mysqlpid-file    = /var/run/mysqld/mysqld.pidsocket        = /var/run/mysqld/mysqld.sockport        = 3306basedir        = /usrdatadir        = /var/lib/mysqltmpdir        = /tmplc-messages-dir    = /usr/share/mysqlskip-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        = 16Mmax_allowed_packet    = 16Mthread_stack        = 192Kthread_cache_size       = 8# This replaces the startup script and checks MyISAM tables if needed# the first time they are touchedmyisam-recover         = BACKUP#max_connections        = 100#table_cache            = 64#thread_concurrency     = 10## * Query Cache Configuration#query_cache_limit    = 1Mquery_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.logexpire_logs_days    = 10max_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]quickquote-namesmax_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 $SRCDIRapt-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 mysqluseradd -g mysql mysql#创建mysql的安装目录以及数据库数据存放目录mkdir -p $INSTALLDIR/mysqlmkdir -p $INSTALLDIR/mysql/data#安装mysqltar -zxvf mysql-5.6.12.tar.gzcd mysql-5.6.12cmake . -DCMAKE_INSTALL_PREFIX=$INSTALLDIR/mysql -DMYSQL_DATADIR=$INSTALLDIR/mysql/data  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1makemake install#设置目录权限cd $INSTALLDIR/mysqlchown -R root:mysql . #把当前目录中所有文件的所有者所有者设为root,所属组为mysqlchown -R mysql:mysql data#将配置拷贝到全局目录下cp support-files/my-default.cnf /etc/my.cnf#创建系统数据库的表#scripts/mysql_install_db --user=mysqlscripts/mysql_install_db --user=mysql --basedir=$INSTALLDIR/mysql --datadir=$INSTALLDIR/mysql/data#设置环境变量cat > /root/export.sh << EOFexport PATH=$PATH:$INSTALLDIR/mysql/bin:$INSTALLDIR/mysql/libEOFecho 'source /root/export.sh' >> /root/.bashrcsource /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 mysqluse 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 $SRCDIRapt-get install -y python-dev libmysqld-devwget http://nchc.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gztar -zxvf MySQL-python-1.2.3.tar.gzcd MySQL-python-1.2.3sed -i -e "s/#mysql_config = \/usr\/local\/bin\/mysql_config/mysql_config=\/usr\/local\/bin\/mysql\/bin\/mysql_config/g" ./site.cfgpython setup.py buildpython setup.py installln -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 = 3306socket = /var/run/mysqld/mysqld.sock[mysqld]user = mysqlpid-file = /var/run/mysqld/mysqld.pidsocket    = /var/run/mysqld/mysqld.sockport = 3306basedir = $INSTALLDIR/mysqldatadir = $INSTALLDIR/mysql/datatmpdir    = /tmplc-messages-dir    = $INSTALLDIR/mysql/shareskip-external-lockingskip-name-resolvebind-address = 0.0.0.0key_buffer = 16Mmax_allowed_packet = 16Mthread_stack = 192Kthread_cache_size = 8myisam-recover = BACKUPquery_cache_limit = 1Mquery_cache_size = 16Mlog_error =$INSTALLDIR/mysql/data/log/mysql/error.logexpire_logs_days = 10max_binlog_size = 100M[mysqldump]quickquote-namesmax_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。

转载地址:http://ivxbi.baihongyu.com/

你可能感兴趣的文章
iOS QQ侧滑菜单(高仿)
查看>>
iOS 扫一扫功能开发
查看>>
iOS app之间的跳转以及传参数
查看>>
iOS __block和__weak的区别
查看>>
Android(三)数据存储之XML解析技术
查看>>
Spring JTA应用之JOTM配置
查看>>
spring JdbcTemplate 的若干问题
查看>>
Servlet和JSP的线程安全问题
查看>>
GBK编码下jQuery Ajax中文乱码终极暴力解决方案
查看>>
jQuery性能优化指南
查看>>
Oracle 物化视图
查看>>
PHP那点小事--三元运算符
查看>>
解决国内NPM安装依赖速度慢问题
查看>>
Brackets安装及常用插件安装
查看>>
在CentOS 7系统上搭建LNMP 环境
查看>>
Centos 7(Linux)环境下安装PHP(编译添加)相应动态扩展模块so(以openssl.so为例)
查看>>
fastcgi_param 详解
查看>>
Nginx配置文件(nginx.conf)配置详解
查看>>
标记一下
查看>>
一个ahk小函数, 实现版本号的比较
查看>>