MySQL编译安装
MySQL编译安装
编译安装可以定制,但安装过程缓慢
四个重要步骤:
解压(tar)
生成(./configure)cmake
编译(make)
安装(make insyall)
cmake
定制功能:存储引擎、字符集、压缩
定制安装位置、数据存放位置、文件位置(socket)
安装MySQL
下载安装包wget -q https://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.42.tar.gz安装epel源wget -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-6.repo安装依赖包yum install -y ncurses-deve1 libaio-devel安装cmakeyum install -y cmake创建用户useradd mysql -s /sbin/nologin -M修改hostsvim /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.16.1.52 db02
解压MySQL源码包tar xf mysql-5.6.42.tar.gz
进入MySQL目录cd mysql-5.6.42
生成
#程序存放位置cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.42 \#数据存放位置-DMYSQL_DATADIR=/application/mysql-5.6.42/data \#socket文件存放位置-DMYSQL_UNIX_ADDR=/application/mysql-5.6.42/tmp/mysql.sock \#使用utf8字符集-DDEFAULT_CHARSET=utf8 \#校验规则-DDEFAULT_COLLATION=utf8_general_ci \#使用其他额外的字符集-DWITH_EXTRA_CHARSETS=all \#支持的存储引擎-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \#禁用的存储引擎-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \#启用zlib库支持(zib、gzib相关)-DWITH_ZLIB=bundled \#启用SSL库支持(安全套接层)-DWITH_SSL=bundled \#启用本地数据导入支持-DENABLED_LOCAL_INFILE=1 \#编译嵌入式服务器支持-DWITH_EMBEDDED_SERVER=1 \#mysql5.6支持了google的c++mock框架,允许下载,否则会安装报错-DENABLE_DOWNLOADS=1 \#禁用debug(默认为禁用)-DWITH_DEBUG=0
编译make安装make install做软连接ln -s /application/mysql-5.6.42/ /application/mysql拷贝配置文件cp support-files/mysql.cnf /etc/my.cnf拷贝mysql启动脚本cp support-files/mysql.server /etc/init.d/mysqld进入mysql初始化脚本目录cd /appilcation/mysql/scripts初始化mysql./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql授权chown -R mysql.mysql /application/mysql启动脚本授权700systemd管理mysql启动vim /usr/lib/systemd/system/mysqld.service[Unit]Description=MySQL ServerDocumentation=man:mysqld(8)Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnfLimitNOFILE = 5000设置开机自启动contos6chkconfig mysqld on设置开机自启动contos7systemctl enable mysqld启动mysql/etc/init.d/mysqld start || systemctl start mysqld(你懂我意思吧)创建tmp目录(5.6.36版本不会自动创建tmp目录)mkdir /application/mysql-5.6.42/tmp添加环境变量echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile个人推荐echo 'PATH=/application/mysql/bin/:$PATH' >/etc/profile.d/mysql.sh生效source /etc/profile.d/mysql.sh设置MySQL密码mysqladmin -uroot password 'hanggege'MySQL登录mysql -uuser -ppassword -Ssocket -hhost(你懂我意思吧)
转载请注明出处 qq:1909345942