当前位置: 澳门新濠3559 > 数据库 > 正文

本文档做了两个MYSQL实例

时间:2019-12-27 19:58来源:数据库
ubuntu install mysql driver 注:本文档做了两个MYSQL实例,多个实例方法以此类推 1.       下载mysql 注意:要将/usr/bin/mysql_install_db替换成 /usr/bin/mysql_install_db --datadir=usr/local/mysql/data/var  ,

ubuntu install mysql driver

注:本文档做了两个MYSQL实例,多个实例方法以此类推

1.       下载mysql

注意:要将/usr/bin/mysql_install_db替换成/usr/bin/mysql_install_db  --datadir=usr/local/mysql/data/var  ,不然会报错"Starting MySQL...The server quit without updating PID file”

 

LINUX操作系统:centOS6.3 64bit数据库一:MYSQL版本:mysql-5.0.56PORT:3306系统目录:/usr/local/mysql3306数据库二:MYSQL版本:mysql-5.1.72PORT:3307系统目录:/usr/local/mysql3307

在http://dev.mysql.com/downloads/mysql/ 官网上下载mysql-5.5.28-linux2.6-i686.tar.gz.

Shell代码  

一.安装开发包:复制代码 代码如下:# yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*二.关闭iptables和SELINUX复制代码 代码如下:# service iptables stop# setenforce 0# vi /etc/sysconfig/selinux---------------SELINUX=disabled---------------三.安装mysql数据库实例1.下载编译包:复制代码 代码如下:# su -# mkdir ~/src# cd src# wget wget 代码如下:# useradd mysql 2).新建mysql下data和log子目录复制代码 代码如下:# mkdir /usr/local/mysql{3306,3307}/data # mkdir /usr/local/mysql{3306,3307}/log3).修改目录的所属者以及所属组权限 复制代码 代码如下:# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/# chmod 750 /usr/local/mysql{3306,3307}/data # chmod 750 /usr/local/mysql{3306,3307}/log 4).创建mysql相关目录并配置权限复制代码 代码如下:# mkdir -p /usr/local/mysql{3306,3307}/etc# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc# mkdir -p /var/run/mysqld{3306,3307}# chown -R mysql.mysql /var/run/mysqld{3306,3307}# mkdir -p /var/lib/mysqld{3306,3307}# chown -R mysql.mysql /var/lib/mysqld{3306,3307}# cp /etc/my.cnf /usr/local/mysql{3306,3307}/etc3.解包编译安装编译数据库一:复制代码 代码如下:# cd ~/src# tar -zxvf mysql-5.0.56.tar.gz # cd mysql-5.0.56 ./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock# make# make install编译数据库二:复制代码 代码如下:# cd ~/src# tar -zxvf mysql-5.1.71.tar.gz # cd mysql-5.1.71./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock# make# make install

2.       解压

sudo sudo apt-get install libmysqlcppconn-dev libmysqlclient-dev libmysql++-dev  

4.编写mysql配置项:数据库一配置:复制代码 代码如下:# vi /usr/local/mysql3306/etc/my.cnf-------------------------------------------------------[mysqld]datadir=/usr/local/mysql3306/datasocket=/tmp/mysql3306.sockuser=mysqlport=3306pid-file=/var/lib/mysqld3306/mysql.pid# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0max_connections= 16384skip-name-resolveskip-lockingkey_buffer = 256Mmax_本文档做了两个MYSQL实例。allowed_packet = 32Mtable_cache = 3072thread_cache_size = 256sort_buffer_size = 16Mread_buffer_size = 4Mread_rnd_buffer_size = 16Mnet_buffer_length = 256Mthread_stack = 8Mquery_cache_size = 128Mquery_cache_limit = 2Mwait_timeout=7200interactive_timeout=7200#loglog-error=/usr/local/mysql3306/log/error.loglog=/usr/local/mysql3306/log/mysql.loglong_query_time=2log-slow-queries= /usr/local/mysql3306/log/slowquery.loglog-bin= /usr/local/mysql3306/log/bin.logexpire_logs_days = 15sync_binlog = 1max_binlog_cache_size = 4294967295local-infile=0[mysqld_safe]log-error=/var/log/mysqld3306.logpid-file=/var/run/mysqld3306/mysqld.pid-------------------------------------------------------数据库二配置:复制代码 代码如下:# vi /usr/local/mysql3307/etc/my.cnf-------------------------------------------------------[mysqld]datadir=/usr/local/mysql3307/datasocket=/tmp/mysql3307.sockuser=mysqlport=3307pid-file=/var/lib/mysqld3307/mysql.pid# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0max_connections= 16384skip-name-resolveskip-lockingkey_buffer = 256Mmax_allowed_packet = 32Mtable_cache = 3072thread_cache_size = 256sort_buffer_size = 16Mread_buffer_size = 4Mread_rnd_buffer_size = 16Mnet_buffer_length = 256Mthread_stack = 8Mquery_cache_size = 128Mquery_cache_limit = 2Mwait_timeout=7200interactive_timeout=7200#loglog-error=/usr/local/mysql3307/log/error.loglog=/usr/local/mysql3307/log/mysql.loglong_query_time=2log-slow-queries= /usr/local/mysql3307/log/slowquery.loglog-bin= /usr/local/mysql3307/log/bin.logexpire_logs_days = 15sync_binlog = 1max_binlog_cache_size = 4294967295local-infile=0[mysqld_safe]log-error=/var/log/mysqld3307.logpid-file=/var/run/mysqld3307/mysqld.pid-------------------------------------------------------

   假如tar包在/home/zdw/software目录下

   www.2cto.com  

5.将mysql的库文件路径加入系统的库文件搜索路径中方法一:直接做软链接复制代码 代码如下:# ln -s /usr/local/mysql3306/lib/mysql /usr/lib/mysql方法二:利用ldconfig导入系统库复制代码 代码如下:# echo "/usr/local/mysql3306/lib" >> /etc/ld.so.conf.d/mysql.conf# ldconfig6.输出mysql的头文件到系统头文件复制代码 代码如下:# ln -s /usr/local/mysql3306/include/mysql /usr/include/mysql注: 此处只需将一个mysql实例的库文件添加到系统库,无需多次添加

#tar -xvf mysql-5.5.28-linux2.6-i686.tar.gz

Shell代码  

7.进入相应实例的安装路径,初始化各自配置脚本数据库一配置:复制代码 代码如下:# cd /usr/local/mysql3306# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3306/data数据库二配置:复制代码 代码如下:# cd /usr/local/mysql3307# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data8.复制mysql启动脚本到系统服务目录,并更改脚本配置复制代码 代码如下:# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3306# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld3307数据库一配置:复制代码 代码如下:# vi /etc/init.d/mysqld3006搜索如下行,红色标注的为添加的参数:---------------------------------------------复制代码 代码如下:basedir=/usr/local/mysql3306datadir=/usr/local/mysql3306/dataconf=/usr/local/mysql3306/etc/my.cnf$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &--------------------------------------------数据库二配置:复制代码 代码如下:# vi /etc/init.d/mysqld3007搜索如下行,红色标注的为添加的参数:---------------------------------------------复制代码 代码如下:basedir=/usr/local/mysql3307datadir=/usr/local/mysql3307/dataconf=/usr/local/mysql3307/etc/my.cnf$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &--------------------------------------------

3.       移动到/usr/local/mysql

[email protected]:~/Downloads$ dpkg -L libmysqlcppconn-dev   

9.系统启动项相关配置数据库一配置:复制代码 代码如下:# chkconfig --add mysqld3306 #添加开机启动服务# chkconfig --level 35 mysqld3306 on #设置mysql启动数据库二配置:复制代码 代码如下:# chkconfig --add mysqld3307 # chkconfig --level 35 mysqld3307 on10.启动mysql数据库一启动:复制代码 代码如下:# service mysqld3306 start 数据库二启动:复制代码 代码如下:# service mysqld3307 start 11 添加mysql命令集到系统全局变量注:如果系统之前未安装mysql客户端,可以将编译好的mysql命令集导入系统全局变量以后就可以直接使用mysql命令集,而不需要使用绝对路径访问.复制代码 代码如下:# echo "PATH=$PATH:/usr/local/mysql3306/bin;export PATH" >> /etc/profile# source /etc/profile12. 设置初始账户,并登陆后台:数据库一:复制代码 代码如下:# /usr/local/mysql3306/bin/mysqladmin -u root password 123456 #设置超级管理员密码# /usr/local/mysql3306/bin/mysql -P3306 -S/tmp/mysql3306.sock -uroot -p123456 #连接数据库

#mv mysql-5.5.28-linux2.6-i686 /usr/local/

/.  

数据库二:# /usr/local/mysql3307/bin/mysqladmin -u root password 123456 #设置超级管理员密码# /usr/local/mysql3307/bin/mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456 #连接数据库

添加快捷方式mysql指向mysql-5.5.28-linux2.6-i686

/usr  

注: 因为加了mysql环境变量,以后系统后台可以直接使用mysql命令登录,这里使用绝对路径是为了规范操作# mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456

#ln -s mysql-5.5.28-linux2.6-i686/ mysql

/usr/share  

13.端口测试:复制代码 代码如下:#lsof -i:3306#lsof -i:3307

4.       安装依赖的lib包:执行/usr/local/mysql/bin/mysqld,报错

/usr/share/doc  

OK,大功告成!

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot               open shared object file: No such file or directory

/usr/share/doc/libmysqlcppconn-dev  

使用apt-cache search libaio,找到如下软件源

/usr/share/doc/libmysqlcppconn-dev/copyright  

libaio-dev - Linux kernel AIO access library - development files

/usr/lib  

libaio1 - Linux kernel AIO access library - shared library

/usr/lib/libmysqlcppconn-static.a  

libaio1-dbg - Linux kernel AIO access library - debugging symbols

/usr/include  

使用#apt-get install libaio1 安装

/usr/include/mysql_driver.h  

5.       配置用户,目录

/usr/include/cppconn  

#groupadd mysql

/usr/include/cppconn/warning.h  

#useradd -r -g mysql mysql

/usr/include/cppconn/exception.h  

#cd /usr/local/mysql

/usr/include/cppconn/sqlstring.h  

#chown -R mysql .

/usr/include/cppconn/datatype.h  

#chgrp -R mysql .

/usr/include/cppconn/connection.h  

6.       初始化mysql

/usr/include/cppconn/driver.h  

    假如当前目录为/usr/local/mysql

/usr/include/cppconn/config.h  

#scripts/mysql_install_db --user=mysql

/usr/include/cppconn/metadata.h  

7.       启动mysql

/usr/include/cppconn/prepared_statement.h  

最简单的启动方式:

/usr/include/cppconn/resultset.h  

#/usr/local/mysql/bin/mysqld --user=mysql

/usr/include/cppconn/resultset_metadata.h  

默认情况下使用/usr/local/mysql/data作为mysql的数据目录,包括数据库文件,log日志。

/usr/include/cppconn/build_config.h  

常用的mysql启动参数:

/usr/include/cppconn/statement.h  

/usr/local/mysql/bin/mysqld  --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  --port=3306 --socket=/tmp/mysql.socks

/usr/include/cppconn/parameter_metadata.h  

推荐的启动mysql

/usr/include/mysql_connection.h  

#/usr/local/mysql/support-files/mysql.server start

/usr/share/doc/libmysqlcppconn-dev/changelog.Debian.gz  

启动完成之后用ps -ef |grep mysql 命令查看是否启动

/usr/lib/libmysqlcppconn.a  

8.       登录mysql

/usr/lib/libmysqlcppconn.so  

#/usr/local/mysql/bin/mysql -u root -p

 

默认密码为空

Shell代码  

 

[email protected]:~/Downloads$ dpkg -L libmysql++-dev  

修改root密码

/.  

mysql>use mysql ;
mysql>update user set password=PASSWORD("123456") where user='root';
mysql>FLUSH PRIVILEGES;

/usr  

9.       关闭mysql

/usr/lib  

最简单的方式

/usr/lib/libmysqlpp.a  

#killall mysqld

/usr/include  

推荐的方式

/usr/include/mysql++  

#/usr/local/mysql/support-files/mysql.server stop

/usr/include/mysql++/autoflag.h  

使用mysql.server stop关闭mysqld会销毁pid文件,并做容错操作,但是最后也是调用kill命令kill mysql。

/usr/include/mysql++/beemutex.h  

 

/usr/include/mysql++/cmdline.h  

关闭mysql,尽量不要用kill -9 mysql_pid或者是killall -9 mysql,否则mysql进程无法做退出处理,就可能会丢失数据,甚至导致表损坏。

/usr/include/mysql++/common.h  

 

/usr/include/mysql++/comparable.h  

10.   浅析mysql.server脚本的启动流程

/usr/include/mysql++/connection.h  

mysql.server脚本可以看到在以下脚本调用mysqld_safe这个bash

/usr/include/mysql++/cpool.h  

$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &

/usr/include/mysql++/datetime.h  

默认情况下,$bindir/mysqld_safe就是/usr/local/mysql/bin/mysqld_safe这个shell,我的本机的调用参数如下:

/usr/include/mysql++/dbdriver.h  

/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/blue-pc.pid

/usr/include/mysql++/exceptions.h  

而mysqld_safe也是一个shell,可以看到在这个脚本在初始化N多变量后,调用

/usr/include/mysql++/field.h  

eval_log_error "$cmd"

/usr/include/mysql++/field_names.h  

这个shell function最后就是调用

/usr/include/mysql++/field_types.h  

 #echo "Running mysqld: [$cmd]" eval "$cmd"

/usr/include/mysql++/insertpolicy.h  

在我本机,这个$cmd就是

/usr/include/mysql++/manip.h  

**/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/blue-pc.err --pid-file=/usr/local/mysql/data/blue-pc.pid

/usr/include/mysql++/myset.h  

参考文章:
本文在Ubuntu11.04和Fedora14下测试成功。**

/usr/include/mysql++/mysql++.h  

 

/usr/include/mysql++/mystring.h  

/usr/include/mysql++/noexceptions.h  

/usr/include/mysql++/null.h  

/usr/include/mysql++/options.h  

/usr/include/mysql++/qparms.h  

/usr/include/mysql++/query.h  

/usr/include/mysql++/querydef.h  

/usr/include/mysql++/refcounted.h  

/usr/include/mysql++/result.h  

/usr/include/mysql++/row.h  

/usr/include/mysql++/scopedconnection.h  

/usr/include/mysql++/sql_buffer.h  

/usr/include/mysql++/sql_types.h  

/usr/include/mysql++/sqlstream.h  

/usr/include/mysql++/ssqls.h  

/usr/include/mysql++/ssqls2.h  

/usr/include/mysql++/stadapter.h  

/usr/include/mysql++/stream2string.h  

/usr/include/mysql++/tcp_connection.h  

/usr/include/mysql++/tiny_int.h  

/usr/include/mysql++/transaction.h  

/usr/include/mysql++/type_info.h  

/usr/include/mysql++/uds_connection.h  

/usr/include/mysql++/utility.h  

/usr/include/mysql++/vallist.h  

/usr/include/mysql++/wnp_connection.h  

/usr/share  

/usr/share/doc  

/usr/share/doc/libmysql++-dev  

/usr/share/doc/libmysql++-dev/copyright  

/usr/share/doc/libmysql++-dev/README.txt.gz  

/usr/lib/libmysqlpp.so  

/usr/share/doc/libmysql++-dev/changelog.Debian.gz  

 

install mysql driver Shell代码 sudo sudo apt-get install libmysqlcppconn-dev libmysqlclient-dev libmysql++-dev www.2cto.com Shell代码 [email protected]:~/Downloads$ dpkg -L l...

编辑:数据库 本文来源:本文档做了两个MYSQL实例

关键词: