数据:
描述事物的符号记录称为数据。特点:数据和关于数据的解释不可分。
数据库:
长期存储在计算机内、有组织、可共享的大量的数据的集合。数据库中的数据按照一定的数据模型组织、描述和存储,具有较小的冗余度、较高的数据独立性和易扩展性,并可为各种用户共享。特点:永久存储、有组织、可共享。
数据库可以多看一下叶金荣先生博客连接
rpm包不能私人定制,不同企业对数据库功能要求不同
[root@server1 ~]# ls
cmake3-3.6.1-2.el7.x86_64.rpm
cmake3-data-3.6.1-2.el7.noarch.rpm
mysql-boost-8.0.21.tar.gz
jsoncpp-devel-0.10.5-2.el7.x86_64.rpm
jsoncpp-0.10.5-2.el7.x86_64.rpm
[root@server1 ~]# du -h mysql-boost-8.0.21.tar.gz
266M mysql-boost-8.0.21.tar.gz
[root@server1 ~]# tar zxf mysql-boost-8.0.21.tar.gz
[root@server1 ~]# yum install cmake3-3.6.1-2.el7.x86_64.rpm cmake3-data-3.6.1-2.el7.noarch.rpm jsoncpp-devel-0.10.5-2.el7.x86_64.rpm -y
[root@server1 ~]# yum install cmake3-3.6.1-2.el7.x86_64.rpm cmake3-data-3.6.1-2.el7.noarch.rpm jsoncpp-devel-0.10.5-2.el7.x86_64.rpm jsoncpp-0.10.5-2.el7.x86_64.rpm -y
## mysql8要求cmake必须是3以上版本
[root@server1 ~]# ln -s /usr/bin/cmake3 /usr/local/bin/cmake
[root@server1 ~]# cmake
Usage
cmake3 [options]
cmake3 [options]
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake3 --help' for more information.
[root@server1 ~]# cd mysql-8.0.21/
[root@server1 mysql-8.0.21]# mkdir build ## cmake ../ 编译的都在bulid,不用可以删掉,保持源码干净
[root@server1 mysql-8.0.21]# cd build/
[root@server1 build]# cmake ../ -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci -DWITH_BOOST=/root/mysql-8.0.21/boost/boost_1_72_0
# 商业化的比较喜欢用cmake
# -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql ##默认配置目录
# -DMYSQL_DATADIR=/data/mysql
## 数据库的数据目录 ## 数据库的存储一般挂的外部存储,如果数据库挂了,数据很安全 #-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock ##mysql的socket,客户端链接的时候需要
# -DWITH_INNOBASE_STORAGE_ENGINE=1 ##需要INNOBASE数据库引擎
# -DSYSCONFDIR=/etc ##mysql配置文件放在/etc
# -DENABLED_LOCAL_INFILE=1 ##支持本地大文件导入数据,短时间大量导入
# -DWITH_EXTRA_CHARSETS=all ##支持本地文件导入
# -DDEFAULT_CHARSET=utf8mb4 ##支持外部扩展字符集 ##8版本用的是:utf8mb4
#-DDEFAULT_COLLATION=utf8mb4_0900_ai_ci ##校验字符集
# -DWITH_BOOST=/root/mysql-8.0.21/boost/boost_1_72_0 ## c++的boost库
Could not find devtoolset gcc
-- Could NOT find Git (missing: GIT_EXECUTABLE)
解决
[root@server1 build]# yum install -y gcc-c++ git
GCC 5.3 or newer is required (-dumpversion says 4.8.5) # gcc版本不够
解决
要安装的包在centos的yum源
网页访问:
在阿里云更新yum源
https://developer.aliyun.com/mirror/centos
下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
[root@server1 build]# cd /etc/yum.repos.d/
[root@server1 yum.repos.d]# ls
dvd.repo redhat.repo
[root@foundation4 ~]# iptables -t nat -I POSTROUTING -s 172.25.4.0/24 -j MASQUERADE
## 让虚拟机可以联网
[root@server1 yum.repos.d]# yum install -y wget
[root@server1 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2020-08-15 11:36:38-- https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 1.81.0.8, 219.144.98.105, 1.81.0.7, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|1.81.0.8|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
100%[======================================>] 2,523 --.-K/s in 0s
2020-08-15 11:36:43 (405 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
[root@server1 yum.repos.d]# ls
CentOS-Base.repo dvd.repo redhat.repo
非阿里云ECS用户会出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' 信息,不影响使用。用户也可自行修改相关配置: eg:
[root@server1 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@server1 yum.repos.d]# vim CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[root@server1 yum.repos.d]# yum repolist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/4): base/x86_64/group_gz | 153 kB 00:00
(2/4): extras/x86_64/primary_db | 206 kB 00:00
(3/4): updates/x86_64/primary_db | 3.8 MB 00:00
(4/4): base/x86_64/primary_db | 6.1 MB 00:01
repo id repo name status
base/x86_64 CentOS-7Server - Base - mirrors.aliyun.com 10,070
dvd rhel7.6 5,152
extras/x86_64 CentOS-7Server - Extras - mirrors.aliyun.com 413
updates/x86_64 CentOS-7Server - Updates - mirrors.aliyun.com 1,112
repolist: 16,747
[root@server1 yum.repos.d]# yum install centos-release-scl -y
[root@server1 yum.repos.d]# ls
CentOS-Base.repo CentOS-SCLo-scl-rh.repo redhat.repo
CentOS-SCLo-scl.repo dvd.repo
安装gcc
[root@server1 yum.repos.d]# yum install devtoolset-7-gcc* -y
[root@server1 yum.repos.d]# scl enable devtoolset-7 bash #只下载gcc不生效,这个命令让他生效
[root@server1 yum.repos.d]# which gcc
/opt/rh/devtoolset-7/root/usr/bin/gcc
[root@server1 yum.repos.d]# gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
依然说版本不够
这是因为之前的编译的缓存,清理重新编译即可
GCC 5.3 or newer is required (-dumpversion says 4.8.5)
[root@server1 build]# ls
CMakeCache.txt CMakeFiles VERSION.dep
[root@server1 build]# rm -fr *
[root@server1 build]# cmake ../ -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci -DWITH_BOOST=/root/mysql-8.0.21/boost/boost_1_72_0
-- No package 'libtirpc' found
No bison found!!
Could not find SASL
[root@server1 build]# yum install bison libtirpc-devel -y
[root@server1 build]# yum install -y cyrus-sasl-devel openldap-devel
[root@server1 build]# make -j2 ## 有几个cpu就写几,没有就直接make #大概40min
[root@server1 build]# make install
编译成功!!!
[root@server1 build]# du -sh
8.5G .
[root@server1 build]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# ls
bin lib LICENSE-test README run var
docs LICENSE man README.router share
include LICENSE.router mysql-test README-test support-files
[root@server1 mysql]# du -sh
2.0G .
[root@server1 mysql]# ls
bin lib LICENSE-test README run var
docs LICENSE man README.router share
include LICENSE.router mysql-test README-test support-files
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# ls
mysqld_multi.server mysql-log-rotate mysql.server
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld # mysql启动脚本
[root@server1 support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10591 Aug 15 14:26 /etc/init.d/mysqld # 确定mysql脚本可执行
[root@server1 support-files]# cd
[root@server1 ~]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/lnmp/mysql #默认安装路径
datadir=/data/mysql #数据目录
socket=/data/mysql/mysql.sock #socket
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@server1 ~]# mkdir /data/mysql -p #建立数据存放的目录
[root@server1 ~]# useradd -M -d /usr/local/lnmp/mysql/ -s /sbin/nologin mysql
## mysql需要用普通用户身份执行,安全 不要创建用户主目录,因为已经有了。不登陆系统
[root@server1 ~]# id mysql
uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)
[root@server1 ~]# chown mysql.mysql /data/mysql/
## 目录的权限授权给mysql,可以让mysql在里面写东西
## 初始化生成的表和数据都在/data/mysql/这个目录里
[root@server1 ~]# cd /usr/local/lnmp/mysql/
[root@server1 mysql]# ls
bin lib LICENSE-test README run var
docs LICENSE man README.router share
include LICENSE.router mysql-test README-test support-files
[root@server1 mysql]# cd bin/
[root@server1 bin]# ls
comp_err mysql_client_test mysqlrouter_plugin_info
ibd2sdi mysql_config mysql_secure_installation
innochecksum mysql_config_editor mysqlshow
lz4_decompress mysqld mysqlslap
myisamchk mysqld_multi mysql_ssl_rsa_setup
myisam_ftdump mysqld_safe mysqltest
myisamlog mysqldump mysqltest_safe_process
myisampack mysqldumpslow mysql_tzinfo_to_sql
my_print_defaults mysqlimport mysql_upgrade
mysql mysqlpump mysqlxtest
mysqladmin mysqlrouter perror
mysqlbinlog mysqlrouter_keyring zlib_decompress
mysqlcheck mysqlrouter_passwd
[root@server1 bin]# pwd
/usr/local/lnmp/mysql/bin # 这个目录里有mysql的命令,需要把这个路径写到环境变量当中
[root@server1 bin]# cd
[root@server1 ~]# vim .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/php/bin:/usr/local/lnmp/mysql/bin
[root@server1 ~]# source .bash_profile
[root@server1 ~]# which mysqld
/usr/local/lnmp/mysql/bin/mysqld
[root@server2 ~]# mysqld --initialize --user=mysql
password is generated for root@localhost: yhs/9p!gXRl<
# yhs/9p!gXRl< 数据库初始密码
[root@server1 ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/server1.err'.
SUCCESS!
#必须初始化才能启动mysql,因为启动mysql需要读/data/mysql/server1.err,初始化之前/data/mysql/这个目录里面没有东西
#开启成功后才能使用数据库
[root@server2 ~]# mysql -p
Enter password: #输入数据库初始化产生的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> alter user root@localhost identified by 'Westos+123'; #将密码设置为Westos+123
Query OK, 0 rows affected (0.01 sec)
MYSQL编译安装完成!!!