CentOS7编译安装MySQL8.0

1、下载mysql8.0.16源码包和cmake源码包

cd /usr/local/src
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.16.tar.gz

cname源码包下载地址:https://cmake.org/download/

我这里下载了一个cmake-3.15.0-rc1.tar.gz

注意mysql的源码包一定不要下错了,下错了会报错:does not appear to contain CMakeLists.txt

 

2、编译安装cmake

    2.1、解压cmake并进入目录

tar zxf cmake-3.15.0-rc1.tar.gz
cd cmake-3.15.0-rc1

    2.2、配置、编译、安装

./configure --prefix=/usr/local/cmake
make
make install

--prefix 参数是配置cmake的安装目录

    2.3、做cmake命令软连接,查看cmake版本

ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
cmake --version

 

3、编译安装mysql8,在安装之前需要升级GCC(传送阵:升级gcc)

    3.1、解压mysql8源码包并进入目录

cd /usr/local/src
tar zxf mysql-boost-8.0.16.tar.gz
cd mysql-8.0.16

    3.2、配置、编译、安装(配置编译报错集合)

mkdir bld
cd bld
cmake ../ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DSYSCONFDIR=/etc \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/src/mysql-8.0.16/boost \
-DFORCE_INSOURCE_BUILD=1 \
-DCMAKE_CXX_COMPILER=/usr/local/gcc/bin/g++ \
-DDEFAULT_CHARSET=utf8
make
make install

 

4、创建数据库用户

useradd -s /sbin/nologin mysql

 

5、创建数据存放目录并修改权限

mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql

 

6、修改配置文件(根据自己的情况来配置)

[mysqld]
port=3306
server-id=1
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock

[client]
socket=/usr/local/mysql/mysql.sock

 

7、初始化数据库并安装ssl

/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
/usr/local/mysql/bin/mysql_ssl_rsa_setup

 

8、复制启动脚本、启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld  start

 

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

      9.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 'admin123‘;
     mysql>flush provoleges;
     mysql>exit;

 

转载于:https://www.cnblogs.com/NanZhiHan/p/11004800.html

你可能感兴趣的:(CentOS7编译安装MySQL8.0)