Centos7源码编译安装mysql8

Centos7源码编译安装mysql8 

 


前面介绍了很多关于mysql的文章,下面主要介绍一下mysql8的源码编译安装

一、基本环境

[root@CentOS-7-x86-64-Minimal-1810 ~]# cd /usr/local/src/

[root@CentOS-7-x86-64-Minimal-1810 src]# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

[root@CentOS-7-x86-64-Minimal-1810 src]# uname -r

5.2.14-1.el7.elrepo.x86_64

二、准备

1. 安装依赖包

[root@CentOS-7-x86-64-Minimal-1810 src]# yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel

2. 下载包

[root@CentOS-7-x86-64-Minimal-1810src]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.17.tar.gz

3. 解压并创建用户和目录

[root@CentOS-7-x86-64-Minimal-1810 src]# tar -xf mysql-boost-8.0.17.tar.gz

[root@CentOS-7-x86-64-Minimal-1810 src]# cd mysql-8.0.17/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# groupadd mysql

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# useradd -r -g mysql -s /sbin/nologin mysql

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# mkdir -p /usr/local/mysql

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# mkdir -p /home/mysql

 

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chown -R mysql.mysql /usr/local/mysql/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chown -R mysql.mysql /data/mysql/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chmod -R 755 /home/mysql/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chmod -R 755 /usr/local/mysql/

三、安装

1. 安装cmake 3.5以上版本

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# yum -y remove cmake

1.1下载二进制包

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cd  /usr/local/src/

[root@CentOS-7-x86-64-Minimal-1810 src]# wget https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.tar.gz

[root@CentOS-7-x86-64-Minimal-1810 src]# tar -xf cmake-3.15.3-Linux-x86_64.tar.g

[root@CentOS-7-x86-64-Minimal-1810 src]# cp -r cmake-3.15.3-Linux-x86_64  /usr/local/cmake

1.2设置环境变量

[root@CentOS-7-x86-64-Minimal-1810 src]# vi /etc/profile

export CMAKE_PATH=/usr/local/cmake

export PATH=$PATH:$CMAKE_PATH/bin

[root@CentOS-7-x86-64-Minimal-1810 src]# source /etc/profile

[root@CentOS-7-x86-64-Minimal-1810 src]# cmake –version

 

2.升级gcc

centos7 默认的 gcc 默认是4.8.5,但是此版本有些程序无法编译。需要新版GCC编译。

 

下面是升级新版gcc,配置永久生效命令。

 

yum -y install centos-release-scl

 

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

 

#临时环境变量保存。

 

scl enable devtoolset-9 bash

 

#到这一步时 使用gcc -v就可以查看版本是最新的

3. 编译安装

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql[A1]  \

-DMYSQL_DATADIR=/home/mysql [A2] \

-DSYSCONFDIR=/etc \

-DMYSQL_TCP_PORT=3306 [A3] \

 -DWITH_BOOST=/opt/mysql-8.0.17/boost/boost_1_69_0\[A4] 

 -DDEFAULT_CHARSET=utf8 \

 -DDEFAULT_COLLATION=utf8_general_ci \

 -DENABLED_LOCAL_INFILE=ON \

 -DWITH_INNODB_MEMCACHED=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

 -DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1;

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# make && make install

4. 初始化数据库

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cd /usr/local/mysql/bin/

[root@CentOS-7-x86-64-Minimal-1810 bin]# ./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql

 

 

[root@CentOS-7-x86-64-Minimal-1810 bin]# echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile

[root@CentOS-7-x86-64-Minimal-1810 bin]# source /etc/profile

[root@CentOS-7-x86-64-Minimal-1810 bin]# cp /usr/local/src/mysql-8.0.17/support-files/mysql.server /etc/init.d/mysqld

[root@CentOS-7-x86-64-Minimal-1810 bin]# vim /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/home/mysql

[root@CentOS-7-x86-64-Minimal-1810 bin]# chmod +x /etc/init.d/mysqld

[root@CentOS-7-x86-64-Minimal-1810 bin]# /etc/init.d/mysqld start

 

[root@CentOS-7-x86-64-Minimal-1810 bin]# vi /etc/my.cnf

 

[client]

port=3306

socket=/tmp/mysql.sock

default-character-set=utf8

#user=root

#password=123

[mysqld]

server-id=1

#skip-grant-tables

port=3306

user=mysql

max_connections=200

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/data/mysql

pid-file=/data/mysql/mysql.pid

init-connect='SET NAMES utf8'

character-set-server=utf8

default-storage-engine=INNODB

log_error=/data/mysql/mysql-error.log

slow_query_log_file=/data/mysql/mysql-slow.log

[mysqldump]

quick

max_allowed_packet=16M

5.登陆

可以无密码登录

[root@CentOS-7-x86-64-Minimal-1810 bin]# mysql -u root -p

四、修改mysql密码(忘记密码)

1. 在配置文件中的[mysqld]下加入skip-grant-tables

vim /etc/my.cnf
      [mysqld]
      skip-grant-tables

       9.2重启mysql

/etc/init.d/mysqld restart

      9.3登录数据库后,修改密码为空。

mysql
    mysql >use mysql;
    mysql >update user set authentication_string="" where user='root';
    mysql >flush privileges;
    mysql > exit;

      9.4在配置文件中删除skip-grant-tables并重启mysql

/etc/init.d/mysqld restart

      9.5登录mysql,修改密码

mysql -uroot -ppassword
     mysql>alter user 'root'@'locahost' identified by 'root@admin123‘;
     mysql>flush privileges;
     mysql>exit;

 

2. 开启远程

    10.1登录mysql

mysql -uroot -ppassword

    10.2创建用户

create user 'root'@'%'  identified by 'admin123';

    10.3设置权限

grant all privileges on *.* to 'root'@'%';
flush privileges;

 


 [A1]安装目录

 [A2]存储数据的路径

 [A3]服务端口

 [A4]注意boost的路径

posted @ 2022-12-22 11:40  禾子、  阅读(1803)  评论(0编辑  收藏  举报