MySQL(一)

简介

MySQL是一个关系型数据库管理系统,由瑞典 Mysql AB 公司开发,属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一。

安装部署

yum源安装

[root@wenzi ~]# ls
anaconda-ks.cfg  mysql80-community-release-el7-10.noarch.rpm  original-ks.cfg
[root@wenzi ~]# yum -y install mysql80-community-release-el7-10.noarch.rpm
[root@wenzi ~]# ls /etc/yum.repos.d/
backup  CentOS-Base.repo  epel.repo  epel-testing.repo  mysql-community-debuginfo.repo  mysql-community.repo  mysql-community-source.repo
[root@wenzi ~]# yum -y install epel-release
[root@wenzi ~]# yum -y info  mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: ftp.iij.ad.jp
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Installed Packages
Name        : mysql-community-server
Arch        : x86_64
Version     : 8.0.34
Release     : 1.el7
Size        : 295 M
Repo        : installed
From repo   : mysql80-community
Summary     : A very fast and reliable SQL database server
URL         : http://www.mysql.com/
License     : Copyright (c) 2000, 2023, Oracle and/or its affiliates. Under GPLv2 license as shown in the Description field.
Description : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
            : and robust SQL (Structured Query Language) database server. MySQL Server
            : is intended for mission-critical, heavy-load production systems as well
            : as for embedding into mass-deployed software. MySQL is a trademark of
            : Oracle and/or its affiliates
            :
            : The MySQL software has Dual Licensing, which means you can use the MySQL
            : software free of charge under the GNU General Public License
            : (http://www.gnu.org/licenses/). You can also purchase commercial MySQL
            : licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
            : the GPL. See the chapter "Licensing and Support" in the manual for
            : further info.
            :
            : The MySQL web site (http://www.mysql.com/) provides the latest news and
            : information about the MySQL software.  Also please see the documentation
            : and the manual for more information.
            :
            : This package includes the MySQL server binary as well as related utilities
            : to run and administer a MySQL server.

[root@wenzi ~]# yum -y install mysql-community-server
[root@wenzi ~]# systemctl start mysqld

修改密码

#查看默认密码
[root@wenzi ~]# grep "password" /var/log/mysqld.log
2023-09-04T17:54:42.391661Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: xax ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin.123';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

#使用新密码登录
[root@wenzi ~]# mysql -uroot -p'Admin.123'
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 10
Server version: 8.0.34 MySQL Community Server - GPL
...

二进制安装

官方文档 MySQL :: MySQL 8.1 Reference Manual :: 2.2 Installing MySQL on Unix/Linux Using Generic Binaries

通用Unix/Linux二进制包MySQL安装布局

目录 目录内容
bin mysqld server, client 和实用程序
docs MySQL info格式手册
man Unix 手册页
include 包括头文件
lib
share 错误消息、字典和用于数据库安装的SQL
support-files 杂项支持文件
[root@wenzi ~]# ls
mysql-8.0.34-linux-glibc2.28-x86_64.tar.gz
#MySQL依赖libaio库
[root@wenzi ~]# yum search libaio
[root@wenzi ~]# yum -y install libaio
[root@wenzi ~]# tar -zx -f mysql-8.0.34-linux-glibc2.28-x86_64.tar.gz -C /usr/local/
[root@wenzi ~]# ln -s /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/ /usr/local/mysql
[root@wenzi ~]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
#创建mysql专用用户和组
[root@wenzi ~]# groupadd mysql
[root@wenzi ~]# useradd -r -g mysql -s /bin/false mysql
#删除系统自带的mysql或mariadb的配置文件,以免影响后续安装
[root@wenzi mysql]# rm -f /etc/my.cnf
#配置环境变量
[root@wenzi ~]# vim /etc/profile.d/mysql80.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@wenzi ~]# source /etc/profile.d/mysql80.sh
[root@wenzi ~]# cd /usr/local/mysql/
#这个文件必须有,暂时不知作用
[root@wenzi mysql]# mkdir mysql-files
[root@wenzi mysql]# chown mysql:mysql mysql-files
[root@wenzi mysql]# chmod 750 mysql-files
[root@wenzi mysql]# chown -R mysql:mysql /usr/local/mysql/
#初始化
[root@wenzi mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by mysqld)
mysqld: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by mysqld)
mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by mysqld)
mysqld: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libcrypto.so.3)
mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)

出现报错,大致意思说找不到相应版本的glibc,错误信息中glibc版本最高位2.28;查看现在系统glibc版本

#现系统上所有的glibc版本,可见最高为2.17,不满足条件,和报错信息符合
[root@wenzi ~]# strings /lib64/libc.so.6 | grep "GLIBC"
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_PRIVATE
...
[root@wenzi mysql]# yum info glibc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
#已安装的版本
Installed Packages
Name        : glibc
Arch        : x86_64
Version     : 2.17
Release     : 317.el7
Size        : 13 M
Repo        : installed
From repo   : anaconda
Summary     : The GNU libc libraries
URL         : http://www.gnu.org/software/glibc/
License     : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Description : The glibc package contains standard libraries which are used by
            : multiple programs on the system. In order to save disk space and
            : memory, as well as to make upgrading easier, common system code is
            : kept in one place and shared between programs. This particular package
            : contains the most important sets of shared libraries: the standard C
            : library and the standard math library. Without these two libraries, a
            : Linux system will not function.

去下载glibc_2.28,地址 Index of /gnu/glibc ,编译安装glibc2.28

[root@wenzi ~]# curl -O http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.xz
[root@wenzi ~]# tar -Jx -f glibc-2.28.tar.xz -C  /usr/local/
[root@wenzi ~]# mkdir /usr/local/glibc-2.28/build
[root@wenzi ~]# cd /usr/local/glibc-2.28/build
[root@wenzi build]# ../configure --prefix=/usr/ --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/glibc-2.28/build':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

出现报错,在$PATH中找不到可接受的C编译器,查看日志 cat config.log

MySQL(一)_第1张图片

应该与gcc有关,查看本机是否安装gcc

MySQL(一)_第2张图片

安装gcc

[root@wenzi build]# yum -y install gcc
[root@wenzi build]# ../configure --prefix=/usr/ --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for readelf... readelf
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking whether g++ can link programs... no
checking for sysdeps preconfigure fragments... aarch64 alpha arm hppa i386 m68k microblaze mips nios2 powerpc riscv s390 sh sparc x86_64 checking whether gcc compiles in -mx32 mode by default... no

checking for use of fpu sysdeps directories... yes
checking for -fstack-protector... yes
checking for -fstack-protector-strong... yes
checking for -fstack-protector-all... yes
checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... yes
checking if compiler warns about alias for function with incompatible types... no
checking sysdep dirs... sysdeps/unix/sysv/linux/x86_64/64 sysdeps/unix/sysv/linux/x86_64 sysdeps/unix/sysv/linux/x86 sysdeps/x86/nptl sysdeps/unix/sysv/linux/wordsize-64 sysdeps/x86_64/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/x86_64 sysdeps/unix sysdeps/posix sysdeps/x86_64/64 sysdeps/x86_64/fpu/multiarch sysdeps/x86_64/fpu sysdeps/x86/fpu sysdeps/x86_64/multiarch sysdeps/x86_64 sysdeps/x86 sysdeps/ieee754/float128 sysdeps/ieee754/ldbl-96 sysdeps/ieee754/dbl-64/wordsize-64 sysdeps/ieee754/dbl-64 sysdeps/ieee754/flt-32 sysdeps/wordsize-64 sysdeps/ieee754 sysdeps/generic
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether /usr/bin/as is GNU as... yes
checking whether /usr/bin/ld is GNU ld... yes
checking for /usr/bin/as... /usr/bin/as
checking version of /usr/bin/as... 2.27, ok
checking for /usr/bin/ld... /usr/bin/ld
checking version of /usr/bin/ld... 2.27, ok
checking for gnumake... no
checking for gmake... gmake
checking version of gmake... 3.82, bad
checking for gnumsgfmt... no
checking for gmsgfmt... no
checking for msgfmt... msgfmt
checking version of msgfmt... 0.19.8.1, ok
checking for makeinfo... no
checking for sed... sed
checking version of sed... 4.2.2, ok
checking for gawk... gawk
checking version of gawk... 4.0.2, ok
checking for bison... no
checking if gcc -B/usr/bin/ is sufficient to build libc... no
checking for nm... nm
checking for python3... no
checking for python... python
configure: error:
*** These critical programs are missing or too old: make bison compiler
*** Check the INSTALL file for required versions.

出现报错,这些关键的程序要么缺少,要么太老了:make bison编译器;检查INSTALL文件以获取所需的版本。

下载make,地址 Index of /gnu/make

[root@wenzi ~]# curl -O https://ftp.gnu.org/gnu/make/make-4.2.tar.gz
[root@wenzi ~]# ls
anaconda-ks.cfg  glibc-2.28.tar.xz  make-4.2.tar.gz  mysql-8.0.34-linux-glibc2.28-x86_64.tar.gz  original-ks.cfg
[root@wenzi ~]# tar -xzvf make-4.2.tar.gz
[root@wenzi ~]# cd make-4.2
[root@wenzi make-4.2]# ls
ABOUT-NLS      ChangeLog     configure.bat  function.c       hash.c       Makefile.ami              NMakefile       README.OS2      strcache.c                  vmsify.c
acinclude.m4   commands.c    COPYING        getloadavg.c     hash.h       makefile.com              os.h            README.VMS      subproc.bat                 vmsjobs.c
aclocal.m4     commands.h    debug.h        getopt1.c        implicit.c   Makefile.DOS              output.c        README.W32      tests                       vms_progname.c
alloca.c       config        default.c      getopt.c         INSTALL      Makefile.in               output.h        remake.c        variable.c                  vpath.c
amiga.c        config.ami    dep.h          getopt.h         job.c        makefile.vms              po              remote-cstms.c  variable.h                  w32
amiga.h        configh.dos   dir.c          gettext.h        job.h        makeint.h                 posixos.c       remote-stub.c   version.c
ar.c           config.h.in   doc            glob             loadapi.c    make.lnk                  read.c          rule.c          vmsdir.h
arscan.c       config.h-vms  dosbuild.bat   gmk-default.h    load.c       make_msvc_net2003.sln     README          rule.h          vms_exit.c
AUTHORS        config.h.W32  expand.c       gmk-default.scm  main.c       make_msvc_net2003.vcproj  README.Amiga    SCOPTIONS       vms_export_symbol.c
build.sh.in    configure     file.c         gnumake.h        make.1       misc.c                    README.customs  signame.c       vms_export_symbol_test.com
build_w32.bat  configure.ac  filedef.h      guile.c          Makefile.am  NEWS                      README.DOS      SMakefile       vmsfunctions.c
[root@wenzi make-4.2]# ./configure
[root@wenzi make-4.2]# make
[root@wenzi make-4.2]# make install
[root@wenzi make-4.2]# rm -rf /usr/bin/make
[root@wenzi make-4.2]# cp ./make /usr/bin/
[root@wenzi make-4.2]# make -v
GNU Make 4.2
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

[root@wenzi ~]# yum -y install bison

再次编译安装glibc2.28

[root@wenzi ~]# cd /usr/local/glibc-2.28/build/
[root@wenzi build]# ../configure --prefix=/usr/ --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for readelf... readelf
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking whether g++ can link programs... no
checking for sysdeps preconfigure fragments... aarch64 alpha arm hppa i386 m68k microblaze mips nios2 powerpc riscv s390 sh sparc x86_64 checking whether gcc compiles in -mx32 mode by default... no

checking for use of fpu sysdeps directories... yes
checking for -fstack-protector... yes
checking for -fstack-protector-strong... yes
checking for -fstack-protector-all... yes
checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... yes
checking if compiler warns about alias for function with incompatible types... no
checking sysdep dirs... sysdeps/unix/sysv/linux/x86_64/64 sysdeps/unix/sysv/linux/x86_64 sysdeps/unix/sysv/linux/x86 sysdeps/x86/nptl sysdeps/unix/sysv/linux/wordsize-64 sysdeps/x86_64/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/x86_64 sysdeps/unix sysdeps/posix sysdeps/x86_64/64 sysdeps/x86_64/fpu/multiarch sysdeps/x86_64/fpu sysdeps/x86/fpu sysdeps/x86_64/multiarch sysdeps/x86_64 sysdeps/x86 sysdeps/ieee754/float128 sysdeps/ieee754/ldbl-96 sysdeps/ieee754/dbl-64/wordsize-64 sysdeps/ieee754/dbl-64 sysdeps/ieee754/flt-32 sysdeps/wordsize-64 sysdeps/ieee754 sysdeps/generic
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether /usr/bin/as is GNU as... yes
checking whether /usr/bin/ld is GNU ld... yes
checking for /usr/bin/as... /usr/bin/as
checking version of /usr/bin/as... 2.27, ok
checking for /usr/bin/ld... /usr/bin/ld
checking version of /usr/bin/ld... 2.27, ok
checking for gnumake... no
checking for gmake... gmake
checking version of gmake... 4.2, ok
checking for gnumsgfmt... no
checking for gmsgfmt... no
checking for msgfmt... msgfmt
checking version of msgfmt... 0.19.8.1, ok
checking for makeinfo... no
checking for sed... sed
checking version of sed... 4.2.2, ok
checking for gawk... gawk
checking version of gawk... 4.0.2, ok
checking for bison... bison
checking version of bison... 3.0.4, ok
checking if gcc -B/usr/bin/ is sufficient to build libc... no
checking for nm... nm
checking for python3... no
checking for python... python
configure: error:
*** These critical programs are missing or too old: compiler
*** Check the INSTALL file for required versions.

出现报错,gcc版本太旧,升级gcc

[root@wenzi build]# yum -y install centos-release-scl
[root@wenzi build]# yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
[root@wenzi build]# scl enable devtoolset-8 bash
[root@wenzi build]# source /opt/rh/devtoolset-8/enable
[root@wenzi build]# echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
[root@wenzi build]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)

以上排错过程参考 解决/lib64/libc.so.6: version `GLIBC_2.28‘ not found (required by_version `glibc_2.28' not found_LLLLLL_03的博客-CSDN博客

再次编译安装glibc2.28

[root@wenzi build]# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
[root@wenzi build]# make
[root@wenzi build]# make install
...
LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl scripts/test-installation.pl /usr/local/glibc-2.28/build/
/usr/bin/ld: cannot find -lnss_test2
collect2: error: ld returned 1 exit status
Execution of gcc -B/usr/bin/ failed!
The script has found some problems with your installation!
Please read the FAQ and the README file and check the following:
- Did you change the gcc specs file (necessary after upgrading from
  Linux libc5)?
- Are there any symbolic links of the form libXXX.so to old libraries?
  Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,
  libm.so should point to the newly installed glibc file - and there should be
  only one such link (check e.g. /lib and /usr/lib)
You should restart this script from your build directory after you've
fixed all problems!
Btw. the script doesn't work if you're installing GNU libc not as your
primary library!
make[1]: *** [Makefile:111: install] Error 1
make[1]: Leaving directory '/usr/local/glibc-2.28'
make: *** [Makefile:12: install] Error 2

出现报错,未能解决,但查到有人说报错可以无视。CentOS 7.6 编译安装最新版本glibc2.30 实录-阿里云开发者社区

继续MySQL初始化

[root@wenzi build]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by mysqld)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)
mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf-lite.so.3.19.4)

出现报错,但关于glibc版本的错误消失了。

第一行错误通常是由于两个不兼容的库版本导致的。CXXABI_1.3.11是libstdc++.so.6库中的一个符号版本。当程序在运行时,动态链接器会尝试寻找并加载符号版本所对应的库。如果找不到或者找到的版本不匹配,就会出现链接错误。

错误信息中 CXXABI相关最高版本为CXXABI_1.3.11

查看本机有无对应版本,本机CXXABI最高为1.3.7

[root@wenzi ~]# strings /usr/lib64/libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_TM_1

查询libstdc++.so.6本机位置

[root@wenzi ~]# find / -name libstdc++.so.6* #ls -l libstdc++.so*
/usr/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6.0.19
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo

安装包含 CXXABI_1.3.11 的 libstdc++.so 包,但是能找到最新版的包 libstdc++-4.8.5-44.el7.x86_64.rpm,地址https://centos.pkgs.org/7/centos-x86_64/libstdc++-4.8.5-44.el7.x86_64.rpm.html

却不包含CXXABI_1.3.11

MySQL(一)_第3张图片

通过安装 Anaconda3 ,里面这个libstdc++.so高版本的包可以直接用。

[mysql]tar安装mysql报错./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.11‘ not found(废弃)_胖胖学编程的博客-CSDN博客

centos安装Anaconda3

[root@wenzi build]# mkdir /usr/local/anaconda
[root@wenzi build]# cd /usr/local/anaconda
[root@wenzi anaconda]# curl -O https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
[root@wenzi anaconda]# ls
Anaconda3-2022.10-Linux-x86_64.sh
[root@wenzi anaconda]# chmod +x Anaconda3-2022.10-Linux-x86_64.sh
[root@wenzi anaconda]# ./Anaconda3-2022.10-Linux-x86_64.sh

此时显示Anaconda的信息,按enter

MySQL(一)_第4张图片

并且会出现More,继续按Enter,出现下图输入yes

MySQL(一)_第5张图片

然后会提示是否修改安装路径,不修改继续回车,最终出现下图,完成安装MySQL(一)_第6张图片

验证

[root@wenzi anaconda]# vim /etc/profile.d/anaconda3.sh
export PATH="/root/anaconda3/bin:$PATH"
[root@wenzi anaconda]# source /etc/profile.d/anaconda3.sh
[root@wenzi anaconda]# python3
Python 3.9.13 (main, Aug 25 2022, 23:26:10)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
KeyboardInterrupt
>>> quit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>>
#输出 Ctrl -D 回到centos命令行
[root@wenzi anaconda]# conda -V
conda 22.9.0

查找anaconda3中的libstdc++.so相关包

[root@wenzi ~]# find / -name libstdc++.so.6
/root/anaconda3/pkgs/libstdcxx-ng-11.2.0-h1234567_1/lib/libstdc++.so.6
/root/anaconda3/lib/libstdc++.so.6
/usr/lib64/libstdc++.so.6
[root@wenzi ~]# ll /root/anaconda3/lib/libstdc*
lrwxrwxrwx 1 root root       19 Sep  6 17:23 /root/anaconda3/lib/libstdc++.so -> libstdc++.so.6.0.29
lrwxrwxrwx 1 root root       19 Sep  6 17:23 /root/anaconda3/lib/libstdc++.so.6 -> libstdc++.so.6.0.29
-rwxrwxr-x 2 root root 17981480 Jun  1  2022 /root/anaconda3/lib/libstdc++.so.6.0.29

查看有无对应 CXXABI_1.3.11 版本,有CXXABI_1.3.11

[root@wenzi ~]# strings /root/anaconda3/lib/libstdc++.so.6.0.29 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_1.3.8
CXXABI_1.3.9
CXXABI_1.3.10
CXXABI_1.3.11
CXXABI_1.3.12
CXXABI_1.3.13
CXXABI_TM_1
CXXABI_FLOAT128
CXXABI_1.3
CXXABI_1.3.11
CXXABI_1.3.2
CXXABI_1.3.6
CXXABI_FLOAT128
CXXABI_1.3.12
CXXABI_1.3.9
CXXABI_1.3.1
CXXABI_1.3.5
CXXABI_1.3.8
CXXABI_1.3.13
CXXABI_1.3.4
CXXABI_TM_1
CXXABI_1.3.7
CXXABI_1.3.10
CXXABI_1.3.3

将anaconda3的libstdc++.so.6.0.29复制到/lib64下,删除原有软链接,新建软链接

[root@wenzi ~]# cp /root/anaconda3/lib/libstdc++.so.6.0.29 /lib64/
[root@wenzi ~]# rm -f /lib64/libstdc++.so.6
[root@wenzi ~]# ln -s /lib64/libstdc++.so.6.0.29 /lib64/libstdc++.so.6
[root@wenzi ~]# ll /lib64/libstdc++.so.6*
lrwxrwxrwx  1 root root       26 Sep  6 17:49 /lib64/libstdc++.so.6 -> /lib64/libstdc++.so.6.0.29
-rwxr-xr-x. 1 root root   995840 Sep 30  2020 /lib64/libstdc++.so.6.0.19
-rwxr-xr-x  1 root root 17981480 Sep  6 17:48 /lib64/libstdc++.so.6.0.29

继续MySQL初始化,成功。最后一行末尾是默认密码

[root@wenzi ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
2023-09-06T10:38:09.775461Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.34-linux-glibc2.28-x86_64/bin/mysqld (mysqld 8.0.34) initializing of server in progress as process 40075
2023-09-06T10:38:09.792484Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-09-06T10:38:10.583537Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-09-06T10:38:12.286737Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 25zsG**(i3XL
[root@wenzi ~]# mysqld_safe --user &
[root@wenzi ~]# cp support-files/mysql.server /etc/init.d/mysql.server
#可通过/etc/init.d/mysql.server start 或 status 或 stop 控制mysql
[root@wenzi ~]# /etc/init.d/mysql.server status
 SUCCESS! MySQL running (2613)
[root@wenzi ~]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or directory

初次登录数据库时出错,缺少 libncurses.so.6

查询本机 libncurses.so.6 文件,可见/usr/lib64目录下无libncurses.so.6,anaconda3里有一个libncurses.so.6 ,将其复制到 /usr/lib64目录下

[root@wenzi ~]# find / -name libncurses.so*
/root/anaconda3/pkgs/ncurses-6.3-h5eee18b_3/lib/libncurses.so.6
/root/anaconda3/pkgs/ncurses-6.3-h5eee18b_3/lib/libncurses.so.6.3
/root/anaconda3/pkgs/ncurses-6.3-h5eee18b_3/lib/libncurses.so
/root/anaconda3/lib/libncurses.so
/root/anaconda3/lib/libncurses.so.6
/root/anaconda3/lib/libncurses.so.6.3
/usr/lib64/libncurses.so.5
/usr/lib64/libncurses.so.5.9
[root@wenzi ~]# cp /root/anaconda3/lib/libncurses.so.6 /usr/lib64/
[root@wenzi ~]# mysql -uroot -p
mysql: error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory

出现错误,处理,道理同上;成功登录数据库

[root@wenzi ~]# find / -name libtinfo.so*
/root/anaconda3/pkgs/ncurses-6.3-h5eee18b_3/lib/libtinfo.so.6
/root/anaconda3/pkgs/ncurses-6.3-h5eee18b_3/lib/libtinfo.so.6.3
/root/anaconda3/pkgs/ncurses-6.3-h5eee18b_3/lib/libtinfo.so
/root/anaconda3/lib/libtinfo.so
/root/anaconda3/lib/libtinfo.so.6
/root/anaconda3/lib/libtinfo.so.6.3
/usr/lib64/libtinfo.so.5
/usr/lib64/libtinfo.so.5.9
[root@wenzi ~]# cp /root/anaconda3/lib/libtinfo.so.6  /usr/lib64/
[root@wenzi ~]# mysql -uroot -p'25zsG**(i3XL'
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.34

Copyright (c) 2000, 2023, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin.123';
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
[root@wenzi ~]# mysql -uroot -p'Admin.123'
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 9
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit
Bye

源码编译安装

MySQL :: MySQL 8.0 Reference Manual :: 2.8.7 MySQL Source-Configuration Options 官方文档

[root@wenzi ~]# ls
anaconda-ks.cfg  mysql-boost-8.0.32.tar.gz  original-ks.cfg
#准备依赖
[root@wenzi ~]# yum -y install epel-release && yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake libudev-devel
[root@wenzi ~]# tar -zx -f mysql-boost-8.0.32.tar.gz -C /usr/local/
[root@wenzi ~]# ln -s /usr/local/mysql-8.0.32/ /usr/local/mysql
[root@wenzi ~]# cd /usr/local/mysql
[root@wenzi mysql]# ls
boost           components       Doxyfile-ignored   include              libchangestreams  man            mysys      router             sql         support-files  vio
client          config.h.cmake   Doxyfile.in        INSTALL              libmysql          mysql          packaging  run_doxygen.cmake  sql-common  testclients
cmake           configure.cmake  doxygen_resources  libbinlogevents      libservices       mysql-test     plugin     scripts            storage     unittest
CMakeLists.txt  Docs             extra              libbinlogstandalone  LICENSE           MYSQL_VERSION  README     share              strings     utilities
[root@wenzi mysql]# cmake . \
-DWITH_BOOST=/usr/local/bootst \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
-- Running cmake version 2.8.12.2
CMake Warning at CMakeLists.txt:82 (MESSAGE):
  Please use cmake3 rather than cmake on this platform


-- Please install cmake3 (yum install cmake3)
CMake Error at CMakeLists.txt:112 (CMAKE_MINIMUM_REQUIRED):
  CMake 3.5.1 or higher is required.  You are running version 2.8.12.2


-- Configuring incomplete, errors occurred!

出现报错,CMake版本太低,需要CMake 3.5.1或更高版本

下载make,地址 Index of /files

[root@wenzi ~]# curl -O https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
[root@wenzi ~]# tar -xz -f cmake-3.7.2.tar.gz -C /usr/local/
[root@wenzi ~]# cd /usr/local/cmake-3.7.2/
[root@wenzi cmake-3.7.2]# ls
Auxiliary         CMakeCPackOptions.cmake.in  CMakeLogo.gif             configure         CTestConfig.cmake     doxygen.config  Modules     Source     Utilities
bootstrap         CMakeGraphVizOptions.cmake  cmake_uninstall.cmake.in  CONTRIBUTING.rst  CTestCustom.cmake.in  Help            Packaging   Templates
CMakeCPack.cmake  CMakeLists.txt              CompileFlags.cmake        Copyright.txt     DartConfig.cmake      Licenses        README.rst  Tests
[root@wenzi cmake-3.7.2]# ./configure && make && make install
#编译安装后发现版本没变化,需要重启
[root@wenzi cmake-3.7.2]# reboot
[root@wenzi ~]# cmake --version
cmake version 3.7.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

继续配置mysql

[root@wenzi mysql]# cmake . \
-DWITH_BOOST=/usr/local/mysql/boost \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
-- Running cmake version 3.7.2
-- Could NOT find Git (missing:  GIT_EXECUTABLE)
-- This is .el7. as found from 'rpm -qf /'
-- Looking for a devtoolset compiler
CMake Warning at CMakeLists.txt:392 (MESSAGE):
  Could not find devtoolset compiler/linker in /opt/rh/devtoolset-11


CMake Warning at CMakeLists.txt:394 (MESSAGE):
  You need to install the required packages:

   yum install devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils



CMake Error at CMakeLists.txt:396 (MESSAGE):
  Or you can set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly.


-- Configuring incomplete, errors occurred!

出现错误,缺少文件,下载相关文件;再次cmake会出现报错,根据报错提示cmake时添加-DFORCE_INSOURCE_BUILD=1 ,再次cmake

[root@wenzi mysql]# yum -y install git && yum -y install centos-release-scl && yum -y install devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils
[root@wenzi mysql]# rm -f CMakeCache.txt
[root@wenzi mysql]# rm -f /etc/my.cnf
[root@wenzi mysql]# cmake . \
-DWITH_BOOST=/usr/local/mysql/boost \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DFORCE_INSOURCE_BUILD=1

编译;安装

[root@wenzi mysql]# make && make install

继续配置MySQL

[root@wenzi ~]# vim /etc/profile.d/mysql80.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@wenzi ~]# source /etc/profile.d/mysql80.sh
[root@wenzi ~]# groupadd mysql && useradd -r -g mysql -s /bin/false mysql && cd /usr/local/mysql/
[root@wenzi mysql]# mkdir mysql-files
[root@wenzi mysql]# chown mysql:mysql mysql-files
[root@wenzi mysql]# chmod 750 mysql-files
[root@wenzi mysql]# chown -R mysql:mysql /usr/local/mysql/
[root@wenzi mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
[root@wenzi mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
2023-09-07T11:40:24.810283Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.32/runtime_output_directory/mysqld (mysqld 8.0.32) initializing of server in progress as process 56935
2023-09-07T11:40:24.812541Z 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.
2023-09-07T11:40:24.812546Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8mb3_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2023-09-07T11:40:24.817945Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-09-07T11:40:25.047872Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-09-07T11:40:25.611765Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Mwl_rVaxM2Lk

初始化完成,末尾是默认密码;上面出现两个警告,建议使用新的UTF8MB4替代旧的。

[root@wenzi ~]# mysqld_safe --user &
[root@wenzi ~]# cp support-files/mysql.server /etc/init.d/mysql.server
[root@wenzi ~]# chmod +x /etc/init.d/mysql.server
#需要重启,不然 /etc/init.d/mysql.server status 等命令会报错
[root@wenzi ~]# reboot
#启动mysql
[root@wenzi ~]# /etc/init.d/mysql.server start

修改密码

[root@wenzi ~]# /etc/init.d/mysql.server status
 SUCCESS! MySQL running (1480)
[root@wenzi ~]# mysql -uroot -p'Mwl_rVaxM2Lk'
mysql> alter user 'root'@'localhost' identified by 'Admin.123';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@wenzi ~]# mysql -uroot -p'Admin.123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
...

你可能感兴趣的:(运维工具,#,MySQL,mysql,数据库,linux,运维)