环境:centos7,redhat7,安装mysql-5.7.26版本
1. 下载源码安装包
官网安装地址:https://downloads.mysql.com/archives/community/
此处我是先把包下载到本地再上传到虚拟机,因为网站是国外的
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
会很慢
1.1解压mysql安装包
[root@lihuaixin ~]# mv mysql-5.7.26.tar.gz /usr/local/src
[root@lihuaixin ~]# cd /usr/local/src/
[root@lihuaixin src]# tar -zxvf mysql-5.7.26.tar.gz
1.2 安装解压boost库mysql
5.7 编译安装需要boost 库
[root@lihuaixin ~]# cd /usr/local/
[root@lihuaixin local]# mkdir boost
[root@lihuaixin local]# cd boost/
[root@lihuaixin boost]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@lihuaixin boost]# tar -zxvf boost_1_59_0.tar.gz
1.3 安装依赖
[root@lihuaixin boost]# yum -y install cmake gcc gcc-c++ bison ncurses ncurses-devel
1.4创建用户和组
[root@lihuaixin boost]# groupadd mysql
[root@lihuaixin boost]# useradd -g mysql -s /sbin/nologin -M mysql
2.配置
进入mysql-5.7.26目录
[
root@lihuaixin src]# cd mysql-5.7.26
[root@lihuaixin mysql-5.7.26]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DWITH_BOOST=/usr/local/boost \
> -DSYSCONFDIR=/etc \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DENABLE_DTRACE=0 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EMBEDDED_SERVER=1
3.编译安装
[root@lihuaixin mysql-5.7.26]# make && make install
[root@lihuaixin mysql-5.7.26]# make clean #清理临时文件
修改目录/usr/local/mysql的属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
创建数据存放目录
[root@lihuaixin ~]# mkdir /opt/data
初始化
[root@lihuaixin ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/opt/data/
2019-08-17T10:40:47.223118Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-17T10:40:48.104070Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-17T10:40:48.255032Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-17T10:40:48.328326Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 79ad4fce-c0db-11e9-a1cb-000c29001102.
2019-08-17T10:40:48.330824Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-17T10:40:48.335435Z 1 [Note] A temporary password is generated for root@localhost: 7I62VE)Mja?g 注意最后生成的这个随机密码,建议保存下来,方便后面登录数据库
[root@lihuaixin ~]# echo '7I62VE)Mja?g' >pass
[root@lihuaixin ~]# cat pass
7I62VE)Mja?g
修改配置文件
复制启动文件,做备份
[root@lihuaixin ~]# cd /usr/local/mysql/support-files/
[root@lihuaixin support-files]# cp mysql.server /etc/init.d/mysqld
[root@lihuaixin support-files]# chmod 755 /etc/init.d/mysqld
修改文件存放路径
[root@chenwanting ~]# vim /etc/init.d/mysqld 查找basedir修改文件路径
basedir= /usr/local/mysql/
datadir= /opt/data
修改mysql配置项
[root@lihuaixin ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir= /opt/data
socket=/tmp/mysql.sock
user = mysql
tmpdir = /opt/data
symbolic-links=0
[root@lihuaixin ~]# ps -ef |grep mysql
[mysqld_safe]
log-error=/opt/data/error.log
pid-file=/opt/data/mysql.pid
启动mysql
[root@lihuaixin ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
root 26928 1 0 18:58 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/lihuaixin.pid
mysql 27116 26928 0 18:58 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/opt/data/error.log --pid-file=/opt/data/lihuaixin.pid --socket=/tmp/mysql.sock
root 27190 1776 0 19:03 pts/1 00:00:00 grep --color=auto mysql
进入数据库,由于没有设置环境变量所有要用绝对路径登录
[root@lihuaixin ~]# /usr/local/mysql/bin/mysql -uroot -p'7I62VE)Mja?g'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
修改密码
mysql> set password = password('qiaoben');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@lihuaixin ~]# /usr/local/mysql/bin/mysql -uroot -p'qiaoben'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 Source distribution
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
如cmake的时候
[root@lihuaixin local]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1
报错如下:
CMake Error at cmake/boost.cmake:76 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
This CMake script will look for boost in . If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:228 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:435 (INCLUDE)
– Configuring incomplete, errors occurred!
See also “/byrd/tools/mysql-5.7.9/CMakeFiles/CMakeOutput.log”.
解决方法:
如果此过程出现error,则执行命令 # rm -rf /opt/mysql-5.6.38/CMakeCache.txt
安装相关依赖包,再重新 执行cmake
添加这两行
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/boost
[root@lihuaixin local]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost