解压源码包

[root@db01 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.40.tar.gz
[root@db01 ~]# ll
-rw-r--r--. 1 root root 32395002 9月  27 13:13 mysql-5.6.40.tar.gz
[root@db01 ~]# tar xf mysql-5.6.40.tar.gz
[root@db01 ~]# cd mysql-5.6.40
[root@db01 mysql-5.6.40]# ls
BUILD           cmd-line-utils   dbug                 include   libmysqld    mysys      README   sql-bench   support-files  vio
client          config.h.cmake   Docs                 INSTALL   libservices  mysys_ssl  regex    sql-common  tests          win
cmake           configure.cmake  Doxyfile-perfschema  libevent  man          packaging  scripts  storage     unittest       zlib
CMakeLists.txt  COPYING          extra                libmysql  mysql-test   plugin     sql      strings     VERSION

编译前安装相关依赖

[root@db01 mysql-5.6.40]# yum -y install cmake ncurses-devel libaio-decel openssl-devel gcc gcc-c++ glibc

生成编译文件

[root@db01 mysql-5.6.40]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 \
-DMYSQL_DATADIR=/application/mysql-5.6.40/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/mysql.sock \
-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 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0

编译安装

[root@db01 mysql-5.6.40]# make && make install

创建mysql用户

[root@db01 ~]# useradd mysql -s /sbin/nologin -M

软链接

[root@db01 ~]# ln -s /application/mysql-5.6.44 /application/mysql

进入目录

[root@db01 ~]# cd /application/mysql/support-files

拷贝MySQL配置文件

[root@db01 ~]# cp my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y

拷贝启动脚本

[root@db01 ~]# cp mysql.server /etc/init.d/mysqld
#添加执行权限
[root@db01 mysql-5.6.44]# chmod +x /etc/init.d/mysqld

初始化数据库

cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql

启动mysql

#修改目录所属
[root@db01 mysql-5.6.40]# chown -R mysql:mysql /application/mysql/
#启动mysql
[root@db01 mysql-5.6.40]# /etc/init.d/mysqld start 
Starting MySQL.Logging to '/application/mysql-5.6.40/data/db01.err'.
SUCCESS!
#创建命令快捷方式
[root@db01 mysql-5.6.40]# ln -s /application/mysql/bin/* /usr/bin/
#或者
[root@db01 ~]# echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile
[root@db01 ~]# tail -1 /etc/profile
[root@db01 ~]# source /etc/profile

systemctl启动以及添加开机自启

[root@db01 application]# cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@db01 application]# systemctl start mysqld
文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
MySQL 数据库
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝