共计 5396 个字符,预计需要花费 14 分钟才能阅读完成。
缺点:后期升级不方便,生产中建议 RPM 包方式安装
CentOS7 默认安装了和 MySQL 有兼容性的 MariaDB 数据库,在我们安装 MySQL5.7 之前为了避免发生冲突首先删除 MariaDB。
# rpm -qa | grep maria
# yum remove mariadb-libs -y
一、基于官方源码包安装
下载 mysql-5.7.22.tar.gz
安装 cmake
# yum -y install cmake
# tar -zxvf mysql-5.7.22.tar.gz -C /usr/src
# cd /usr/src/mysql-5.7.22
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DMYSQL_USER=mysql
— Running cmake version 2.8.11
— Configuring with MAX_INDEXES = 64U
— CMAKE_GENERATOR: Unix Makefiles
— SIZEOF_VOIDP 8
— MySQL 5.7.22
— Packaging as: mysql-5.7.22-Linux-x86_64
— Downloading boost_1_59_0.tar.gz to /usr/local/boost
—
— Download failed, error: 35;”SSL connect error”
CMake Error at cmake/boost.cmake:194 (MESSAGE):
You can try downloading
http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
manually using curl/wget or a similar tool
Call Stack (most recent call first):
CMakeLists.txt:506 (INCLUDE)
— Configuring incomplete, errors occurred!
解决:下载 boost_1_59_0.tar.gz,放在 /usr/local/boost 下
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DMYSQL_USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
…
— Check size of wint_t
— Check size of wint_t – done
— Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on RedHat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:534 (MYSQL_CHECK_EDITLINE)
— Configuring incomplete, errors occurred!
解决:
#yum -y install ncurses-devel
# rm -rf /usr/src/mysql-5.7.22/CMakeCache.txt
# gmake
# make install
安装之后的一些配置:
# cd /usr/local/mysql/support-files/
]# ll mysql.server
-rwxr-xr-x 1 root root 10569 Apr 20 11:11 mysql.server
# cp mysql.server /etc/init.d/mysql
# cd /var/lib/
# mkdir mysql
# chown mysql. mysql
# vi /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
socket = /tmp/mysqld.sock
mysql_install_db 被废弃了,取而代之的是 mysqld –initialize
# /usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf –initialize –datadir=/var/lib/mysql –basedir=/usr/local/mysql –user=mysql
2018-04-20T07:49:28.669315Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-20T07:49:29.022395Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-20T07:49:29.090056Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-20T07:49:29.151786Z 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: 5ae072ef-446f-11e8-aa2d-0050568810c7.
2018-04-20T07:49:29.153819Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-04-20T07:49:29.155286Z 1 [Note] A temporary password is generated for root@localhost: ;1ruP:p6R8te
# ll /var/lib/mysql/
总用量 110628
-rw-r—– 1 mysql mysql 56 4 月 20 15:49 auto.cnf
-rw-r—– 1 mysql mysql 417 4 月 20 15:49 ib_buffer_pool
-rw-r—– 1 mysql mysql 12582912 4 月 20 15:49 ibdata1
-rw-r—– 1 mysql mysql 50331648 4 月 20 15:49 ib_logfile0
-rw-r—– 1 mysql mysql 50331648 4 月 20 15:49 ib_logfile1
drwxr-x— 2 mysql mysql 4096 4 月 20 15:49 mysql
drwxr-x— 2 mysql mysql 8192 4 月 20 15:49 performance_schema
drwxr-x— 2 mysql mysql 8192 4 月 20 15:49 sys
# systemctl start mysql
# ps -ef|grep mysql
# vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
# mysql
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
配置文件中添加如下一行,跳过密码验证
# cat /etc/my.cnf
[mysqld]
skip-grant_tables
重启 MySQL
# systemctl restart mysql
# mysql
mysql> update mysql.user set authentication_string=password(‘Oracle’) where user=’root’ ;
再次重启 MySQL
# systemctl restart mysql
# mysql
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password(‘123456’);
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
+——————–+
二、基于官方源代码 RMP 构建自定义 MySQLRPM(一般用于企业内部开发,生产中还是 MySQL 包的方式安装)
创建一个普通用户,用于构建自定义的 RPM 包
# useradd tubeliu
# cp mysql-community-5.7.22-1.el7.src.rpm /home/tubeliu/
# chown tubeliu.tubeliu /home/tubeliu/ -R
# yum list | grep rpm-build
# yum -y install rpm-build
# su – tubeliu
ls
mysql-community-5.7.22-1.el7.src.rpm
$ rpmbuild ~
错误:文件 /home/tubeliu 不是常规文件。
$ ls
mysql-community-5.7.22-1.el7.src.rpm rpmbuild
$ cd rpmbuild/
$ ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
$ cd ..
$ ls
mysql-community-5.7.22-1.el7.src.rpm rpmbuild
$ rpm -ivh mysql-community-5.7.22-1.el7.src.rpm
正在升级 / 安装 …
1:mysql-community-5.7.22-1.el7 ################################# [100%]
$ cd rpmbuild/
$ ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
$ ls -R
.:
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
./BUILD:
./BUILDROOT:
./RPMS:
./SOURCES:
boost_1_59_0.tar.bz2 filter-requires.sh mysql-5.7.22.tar.gz
filter-provides.sh mysql-5.6.37.tar.gz
./SPECS:
mysql.spec
./SRPMS:
$ cd SPECS/
$ vi mysql.spec
$ rpmbuild -bb mysql.spec