加载中...
MySQL部署(源码编译)
发表于:2021-07-18 | 分类: 数据库
字数统计: 11k | 阅读时长: 10 mins.分钟 | 阅读量:

MySQL8.0.25 源码编译部署

环境介绍

  • centos 8.3
  • 数据库版本:MySQL-8.0.25
  • gcc版本:
    • 7系列系统默认GCC版本低不支持安装MySQL8以上版本的数据,需要升级GCC版本,
    • 8系列版本的系统不需要升级GCC
    • 如果需要如何升级 点这

安装cmake工具

[root@test mysql-8.0.25]# dnf -y install cmake3

源码编译

[root@test mysql-8.0.25]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=system \
-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 \
-DCOMPILATION_COMMENT="zsd edition" \
-DWITH_BOOST=/usr/local/mysql/mysql-8.0.25/boost/boost_1_73_0/ \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/3306/mysql.sock \
-DSYSCONFDIR=/usr/local/mysql/data/3306  \
-DFORCE_INSOURCE_BUILD=1

报错:

一、警告不要在源码中构建
CMake Error at CMakeLists.txt:382 (MESSAGE):
  Please do not build in-source.  Out-of source builds are highly
  recommended: you can have multiple builds for the same source, and there is
  an easy way to do cleanup, simply remove the build directory (note that
  'make clean' or 'make distclean' does *not* work)
  You *can* force in-source build by invoking cmake with
  -DFORCE_INSOURCE_BUILD=1
二、缺少依赖
①  CMake Error at cmake/ssl.cmake:61 (MESSAGE):
  PleaseCMake Error at cmake/readline.cmake:71 (MESSAGE):
②  Curses library not found.  Please install appropriate package, install the appropriate openssl developer package.
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
③ CMake Warning at cmake/rpc.cmake:40 (MESSAGE):
  Cannot find RPC development libraries.  You need to install the required
  packages:

    Debian/Ubuntu:              apt install libtirpc-dev
    RedHat/Fedora/Oracle Linux: yum install libtirpc-devel
    SuSE:                       zypper install glibc-devel
三、依赖

安装依赖:

注意: rpcgen源没有需下载

下载地址

[root@test mysql-8.0.25]# dnf -y install openssl-devel
[root@test mysql-8.0.25]# dnf -y install ncurses-devel
[root@test mysql-8.0.25]# rm -rf CMakeCache.txt
[root@test mysql-8.0.25]# yum -y install libtirpc-devel
[root@test mysql-8.0.25]# wget http://mirror.centos.org/centos/8/PowerTools/aarch64/os/Packages/rpcgen-1.3.1-4.el8.aarch64.rpm
[root@test mysql-8.0.25]# dnf --enablerepo=powertools install rpcgen

再次构建:

[root@test mysql-8.0.25]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=system \
-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 \
-DCOMPILATION_COMMENT="zsd edition" \
-DWITH_BOOST=/usr/local/mysql/mysql-8.0.25/boost/boost_1_73_0/ \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/3306/mysql.sock \
-DSYSCONFDIR=/usr/local/mysql/data/3306 \
-DFORCE_INSOURCE_BUILD=1
[root@test mysql-8.0.25]# make -j4
[root@test mysql-8.0.25]# make install

配置用户

创建MySQL用户和用户组

[root@test mysql]# groupadd mysql
[root@test mysql]# useradd  -r -g mysql  -s /bin/false mysql

初始化数据目录

① 修改目录权限

[root@test mysql]# chown -R mysql .

② 初始化数据目录

[root@test mysql]# bin/mysqld --initialize --user=mysql

通过mysqld初始化data目录时,如果使用--initialize选项,则会为'root'@'localhost'用户创建一个随机密码。该密码会打印在控制台,如下所示行中末尾就是临时密码:

2021-07-18T13:02:48.598005Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 87376
2021-07-18T13:02:48.621612Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-07-18T13:02:48.621622Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2021-07-18T13:02:48.632207Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-07-18T13:02:49.645548Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-07-18T13:02:51.981723Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: e2%TeUjfTg0N

复制启动脚本、启动

[root@test mysql]# cp support-files/mysql.server /etc/init.d/mysqld

启动失败(报错)

原因:启动时候没有找到对应3306目录

[root@test mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/test.err'.
2021-07-18T15:13:37.356447Z mysqld_safe Directory '/usr/local/mysql/3306' for UNIX socket file don't exists.
The server quit without updating PID file (/usr/local/mysql[失败]test.pid).

解决方法:

[root@test mysql]# mkdir 3306
[root@test mysql]# chown mysql:mysql 3306/

重新启动:

[root@test mysql]# bin/mysqld_safe --user=mysql &

MySQL命令软连接到/usr/local/bin/mysql用户可以方便使用MySQL命令

[root@test bin]# ln  -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

登陆数据库:

[root@test mysql]# bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.25

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

ERROR报错:{需要重置密码}

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456'
上一篇:
Grafana
下一篇:
Ansible
本文目录
本文目录