MySQL基础之一:编译安装
安装包
链接:https://pan.baidu.com/s/1z61eamGtHYFnXBHORSzuhQ
提取码:nsvr
1.安装依赖包
[root@localhost ~]# yum install gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make libaio libaio-devel autoconf bzr bison libtool -y
2.安装cmake
[root@localhost ~]# tar –zxvf cmake-3.14.5.tar.gz –C /usr/local
[root@localhost ~]# cd /usr/local/cmake-3.14.5 && ./bootstrap
[root@localhost ~]# make -j 8 && make install
3.安装Boost(拷贝至/usr/local/boost目录)
[root@localhost ~]# tar -zxf boost_1_59_0.tar.gz –C /usr/local/src
[root@localhost ~]# mkdir –p /usr/local/boost
[root@localhost ~]# mv /usr/local/src/boost_1_59_0 /usr/local/boost
4.解压MySQL源码包
[root@localhost ~]# tar –zxvf mysql-5.7.26.tar.gz –C /usr/local
5.准备MySQL数据,日志等路径,并创建mysql用户,赋予mysql用户相关文件夹权限
[root@localhost ~]# mkdir -p /usr/local/mysql /var/log/mysql /data/mysql
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -g mysql -r -d /data/mysql mysql
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql /var/log/mysql /data/mysql
6.编译安装
[root@localhost ~]# cd /usr/local
[root@localhost local]# ln -sv mysql-5.7.26 mysql && cd /usr/local/mysql
[root@localhost mysql]# cmake .\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DSYSCONFDIR=/etc/my.cnf \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_BOOST=/usr/local/boost \
[root@localhost local]# make –j 8 && make install
7.编辑my.cnf文件
[root@localhost ~]# mv /etc/my.cnf /etc/my.cnf.bak && vim /etc/my.cnf
#######################################################################
[mysqld]
datadir = /data/mysql
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
user = mysql
port = 3306
slow_query_log_file = /var/log/mysql/slow.log
slow_query_log = 1
symbolic-links = 0
log-error=/var/log/mysql/mysql_error.log
#######################################################################
8.加入环境变量
[root@localhost ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH’ >> /etc/profile
[root@localhost ~]# source /etc/profile
9.初始化MySQL
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost ~]# mysqld --initialize --user=mysql \
--datadir=/data/mysql \
--basedir=/usr/local/mysql \
--socket=/tmp/mysql.sock \
--log-error=/var/log/mysql/mysql_error.log \
--log-bin=/var/log/mysql/mysql-bin \
--pid-file=/data/mysql/mysql.pid
10.添加MySQL服务
[root@localhost ~]# cd /usr/local/mysql/support-files
[root@localhost support-files]# cp –ra mysql.server /etc/init.d/mysqld
[root@localhost support-files]# chmod +x /etc/init.d/mysqld
11.启动MySQL
[root@localhost ~]# /etc/init.d/mysqld start
12.查看mysql进程
[root@localhost ~]# ps aux | grep mysql
13.查找mysql初始密码
[root@localhost ~]# grep 'temporary password' /var/log/mysql/mysql_error.log
14.初次登录,修改密码
[root@localhost ~]# mysql -uroot -p
mysql > set password=password('Password1!');