Centos环境下mysql源码编译安装

前端之家收集整理的这篇文章主要介绍了Centos环境下mysql源码编译安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



yum -y installgccgcc-c++ncurses-develperl

##从MysqL5.5起,MysqL源码安装开始使用cmake了,设置源码编译配置脚本。
tar -zxvfcmake-2.8.12.tar.gz
cdcmake-2.8.12
./bootstrap && make && make install

mkdir -p /usr/local/MysqL

tar -zxvf MysqL-5.6.37.tar.gz
cdMysqL-5.6.37
/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL/ -DMysqL_DATADIR=/data2/MysqLdb -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMysqL_TCP_PORT=3308 -DMysqL_UNIX_ADDR=/usr/local/MysqL/data/MysqL.sock -DMysqL_USER=MysqL -DWITH_DEBUG=0
rmCMakeCache.txt #试验删不删除的影响,试过没删除也没影响
make
make install

mkdir -p /data2/MysqLdb
chown -R MysqL:MysqL /usr/local/MysqL
chown -R MysqL:MysqL /data2/MysqLdb

cp/usr/local/MysqL/support-files/my-default.cnf/etc/my.cnf
chown MysqL:MysqL /etc/my.cnf
##my.cnf重新配置参数,编译阶段的参数没写到这个配置文件去。
#文件配置
vim /etc/my.cnf
basedir =/usr/local/MysqL
datadir =/data2/MysqLdb
port =3308
# server_id = .....
socket =/usr/local/MysqL/data/MysqL.sock

[MysqLd_safe]
log-error=/usr/local/MysqL/log/MysqLd.log
pid-file=/usr/local/MysqL/run/MysqLd/MysqLd.pid

default-storage-engine=MyISAM
server-id = 1
innodb_buffer_pool_size = 21M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

#Because the MysqL server,MysqLd,must access the data directory when it runs later,you should either runMysqL_install_dbfrom the same system account that will be used for runningMysqLd
/usr/local/MysqL/scripts/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL --datadir=/data2/MysqLdb

##指定配置文件
##/usr/local/MysqL/scripts/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL --datadir=/data2/MysqLdb --defaults-file=/usr/local/MysqL/my.cnf

mkdir -p /usr/local/MysqL/log
chown MysqL:MysqL /usr/local/MysqL/log/
mkdir -p /usr/local/MysqL/run/MysqLd/
chown -R MysqL:MysqL /usr/local/MysqL/run/MysqLd/
touch /usr/local/MysqL/log/MysqLd.log
chown MysqL:MysqL /usr/local/MysqL/log/MysqLd.log


#To start a second server,provide different--socketand--portoption values,and pass a--datadir=dir_nameoption toMysqLd_safeso that the server uses a different data directory.
MysqLd_safe --socket=file_name --port=port_number--defaults-file=/usr/local/MysqL/my.cnf


#安全模式启动
/usr/local/MysqL/bin/MysqLd_safe --socket=/usr/local/MysqL/data/MysqL.sock --port=3308 --defaults-file=/usr/local/MysqL/my.cnf

#开启MysqL服务
/usr/local/MysqL/support-files/MysqL.server start

#密码为空,如果能登陆上,则安装成功
/usr/local/MysqL/bin/MysqL -u root -p

自定义带sock文件
/usr/local/MysqL/bin/MysqL -uroot -p -S /usr/local/MysqL/data/MysqL.sock

后续步骤:
cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd-lastest
vim /etc/profile
MysqL_PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib
export MysqL_PATH

source /etc/profile
##添加到系统运行级别
chkconfig--level35MysqLdon
##查看端口占用
netstat-antlp|grep3308

MysqLadmin-urootpassword'123456'


/usr/local/MysqL/bin/MysqLd_safe --skip-grant-tables

问题:
ERROR 2002 (HY000): Can't connect to local MysqL server through socket '/tmp/MysqL.sock' (2)
解决
新建一个链接或在MysqL中加入-S参数,直接指出MysqL.sock位置。
ln -s /usr/local/MysqL/data/MysqL.sock /tmp/MysqL.sock
/usr/local/MysqL/bin/MysqL -u root -S /usr/local/MysqL/data/MysqL.sock


原文链接:https://www.f2er.com/centos/376342.html

猜你在找的CentOS相关文章