查看: 1648|回复: 0

[Mysql数据库] cmake源码编译安装mysql-5.5.32:多实例遇到的坑

发表于 2018-3-9 08:00:02

坑1:找不到mysql-5.5.32.tar.gz 源码包
费劲了很多力气才找到:
mysql 源码包下载地址:
https://downloads.mysql.com/archives/community/

下载路径
https://downloads.mysql.com/archives/get/file/mysql-5.5.32.tar.gz
授人以鱼,我是怎么找到的?

cmake源码编译安装mysql-5.5.32:多实例遇到的坑

坑2:cmake配置报错因为\后面有空格导致的,cmake编译参数正确的为如下:
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0

坑3:mysql多实例执行启动后,端口没有启动,查看日志发现报错。
[root@db02 3306]# /data/3306/mysql start
Starting MySQL...
[root@db02 3306]# /data/3307/mysql start
Starting MySQL...
[root@db02 3306]# netstat -lntup|grep 330

[root@db02 3306]# cat mysql_oldboy3306.err
180302 12:29:03 mysqld_safe Starting mysqld daemon with databases from /application/3306/data
180302 12:29:03 [Warning] Can't create test file /application/3306/data/db02.lower-test
180302 12:29:03 [Warning] Can't create test file /application/3306/data/db02.lower-test
/application/mysql-5.5.32/bin/mysqld: Can't change dir to '/application/3306/data/' (Errcode: 2)
180302 12:29:03 [ERROR] Aborting

180302 12:29:03 [Note] /application/mysql-5.5.32/bin/mysqld: Shutdown complete

180302 12:29:03 mysqld_safe mysqld from pid file /data/3306/mysqld.pid ended

关键报错日志点为:
180302 12:29:03 [Warning] Can't create test file /application/3306/data/db02.lower-test
180302 12:29:03 [Warning] Can't create test file /application/3306/data/db02.lower-test
/application/mysql-5.5.32/bin/mysqld: Can't change dir to '/application/3306/data/' (Errcode: 2)

经过仔细检查是因为多实例配置文件中把datadir路径指向了/application/3306/data导致的。
3307实例报错也是一样的。
修改3306和3307多实例my.cnf中的datadir= /data/3307/data 后再启动两个实例后ok
[root@db02 3306]# /data/3306/mysql start
Starting MySQL...
[root@db02 3306]# /data/3307/mysql start
Starting MySQL...
[root@db02 3306]# netstat -lntup|grep 330
tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN 19701/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:
LISTEN 20418/mysqld

虽然折腾了半天,但是仍很欣慰解决了问题,这里需要感谢一下,http://zpz.name/1592/
给我提供如下参考:让我焕然大悟

**解决编译MySQL后的错误:Can’t change dir to ‘/var/mysql-DMYSQL_UNIX_ADDR=/var/mysql/mysqld.sock/’
一下时可能的问题和解决方案:

1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data” 然后重新启动mysqld!

2.可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9 进程号”杀死,然后重新启动mysqld!

3.可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !http://blog.rekfan.com/?p=186

4.mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data

5.skip-federated字段问题
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。

6.错误日志目录不存在
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限

7.selinux惹的祸,如果是centos系统,默认会开启selinux
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。**

4 最后我把正确的多实例的配置文件发一下:
[root@db02 3307]# tree /data
/data
├── 3306
│ ├── data
│ ├── my.cnf
│ └── mysql
└── 3307
├── data
├── my.cnf
└── mysql
3306的my.cnf

[root@db02 3306]# cat my.cnf
[client]
port = 3306
socket = /data/3306/mysql.sock

[mysql]
no-auto-rehash

[mysqld]
user = mysql
port = 3306
socket = /data/3306/mysql.sock
basedir = /application/mysql
datadir = /data/3306/data
open_files_limit = 1024
back_log =600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2K
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
pid-file = /data/3306/mysql.pid
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db = mysql

server-id = 1

innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M

[mysqld_safe]
log-error = /data/3306/mysql_oldboy3306.err
pid-file = /data/3306/mysqld.pid

3307的my.cnf和3306一样,只是把3306修改为3307,并且把server-id=1修改为其他数字比如,2,3,4,5等等

3306的mysql启动文件如下:3306的mysql启动文件就是把3306中的启动文件中带3306修改为330即可。
[root@db02 3306]# cat mysql
#!/bin/sh
#################################################
#this scripts is created by oldboy at 2007-06-09
#oldboy QQ:31333741
#site:http://www.etiantian.org
#blog:http://oldboy.blog.51cto.com
#oldboy trainning QQ group: 208160987 226199307 44246017
################################################
#init
port=3306
mysql_user="root"
mysql_pwd="123456"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
else
printf "MySQL is running...\n"
exit
fi
}

#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}

#restart function
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}

case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac



回复

使用道具 举报