2022-03-19

1、在阿里云服务器搭建openv-p-n(有条件的同学再做)
2、通过编译、二进制安装MySQL5.7
二进制安装
准备相关包

[root@centos8 ~]# yum -y install libaio numactl-libs

创建用户和组

[root@centos8 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql

创建目录并设置权限

[root@centos8 ~]# mkdir /data/mysql
[root@centos8 ~]# chown mysql:mysql /data/mysql

准备二进制文件包

[root@centos8 ~]# tar xvf mysql-5.7.36-linux-glibc2.12-x86_64.tar -C /usr/local
[root@centos8 ~]# cd /usr/local
[root@centos8 local]# tar xvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@centos8 local]# ln -sv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
[root@centos8 local]# chown -R root:root /usr/local/mysql/

添加PATH路径

[root@centos8 local]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos8 local]# . /etc/profile.d/mysql.sh

准备配置文件

[root@centos8 local]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock

初始化数据库文件
注意:如果启动提示pid文件有问题,删除/data/mysql下文件重新初始化

[root@centos8 local]# mysqld --initialize --user=mysql --datadir=/data/mysql

[root@centos8 mysql]# ll /data/mysql/
total 122964
-rw-r----- 1 mysql mysql       56 Mar 19 11:30 auto.cnf
-rw------- 1 mysql mysql     1680 Mar 19 11:30 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 Mar 19 11:30 ca.pem
-rw-r--r-- 1 mysql mysql     1112 Mar 19 11:30 client-cert.pem
-rw------- 1 mysql mysql     1680 Mar 19 11:30 client-key.pem
-rw-r----- 1 mysql mysql      436 Mar 19 11:30 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Mar 19 11:31 ibdata1
-rw-r----- 1 mysql mysql 50331648 Mar 19 11:31 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Mar 19 11:30 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Mar 19 11:31 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Mar 19 11:30 mysql
-rw-r----- 1 mysql mysql     4725 Mar 19 11:31 mysql.log
-rw-r----- 1 mysql mysql        6 Mar 19 11:31 mysql.pid
srwxrwxrwx 1 mysql mysql        0 Mar 19 11:31 mysql.sock
-rw------- 1 mysql mysql        6 Mar 19 11:31 mysql.sock.lock
drwxr-x--- 2 mysql mysql     8192 Mar 19 11:30 performance_schema
-rw------- 1 mysql mysql     1680 Mar 19 11:30 private_key.pem
-rw-r--r-- 1 mysql mysql      452 Mar 19 11:30 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 Mar 19 11:30 server-cert.pem
-rw------- 1 mysql mysql     1680 Mar 19 11:30 server-key.pem
drwxr-x--- 2 mysql mysql     8192 Mar 19 11:30 sys

准备服务脚本,并启动服务

[root@centos8 local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos8 local]# chkconfig --add mysqld
[root@centos8 local]# service mysqld start

修改密码

[root@centos8 mysql]# grep password /data/mysql/mysql.log
2022-03-19T03:30:41.377532Z 1 [Note] A temporary password is generated for root@localhost: 1/sHpGWxmXjG

[root@centos8 mysql]# mysqladmin -uroot -p'1/sHpGWxmXjG' password 123456

安全初始化

[root@centos8 local]# mysql_secure_installation

测试登录
登录报错mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

[root@centos8 mysql]# yum -y install libncurses

[root@centos8 mysql]# mysql -uroot -p123456
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 6
Server version: 5.7.36 MySQL Community Server (GPL)

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.

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

mysql>

编译安装
安装相关依赖包

[root@centos8 ~]# yum -y install gcc gcc-c++ cmake bison zlib-devel libcurl-devel  boost-devel   ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper libtirpc-devel

准备用户和数据目录

[root@centos8 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql

准备数据库目录

[root@centos8 ~]# mkdir /data/mysql
[root@centos8 ~]# chown mysql.mysql /data/mysql

下载源码包

[root@centos8 ~]# tar xf mysql-5.7.36.tar.gz -C /usr/local/
[root@centos8 ~]# cd /usr/local
#mariadb-10.2.18.tar.gz

源码编译安装 MySQL

[root@centos8 local]# cd mysql-5.7.36/
[root@centos8 mysql-5.7.36]# cmake . \
-DCMAKE_INSTALL_PREFIX=/apps/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DWITH_BOOST=/usr/local/boost \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

# 报错
CMake Error at cmake/boost.cmake:88 (MESSAGE)
.....
#解决方法
[root@centos8 mysql-5.7.36]# cd /usr/local/
[root@centos8 boost]# mkdir boost
[root@centos8 boost]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download

# 报错
CMake Error at cmake/rpc.cmake:76 (MESSAGE):
  Could not find rpc/rpc.h in /usr/include or /usr/include/tirpc
# 解决办法
[root@centos8 ~]# wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4.2/rpcsvc-proto-1.4.2.tar.xz
[root@centos8 ~]# tar xf rpcsvc-proto-1.4.2.tar.xz
[root@centos8 ~]# cd rpcsvc-proto-1.4.2/
[root@centos8 rpcsvc-proto-1.4.2]# ./configure
[root@centos8 rpcsvc-proto-1.4.2]# make && make install
# 编译安装完后发现还是报错,解决办法
[root@centos8 ~]#yum install -y libtirpc-devel

[root@centos8 boost]# tar xf boost_1_78_0.tar.bz2

[root@centos8 mysql-5.7.36]# make && make install

准备环境变量

[root@centos8 local]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos8 local]# . /etc/profile.d/mysql.sh

准备配置文件

[root@centos8 mysql]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock

生成数据库文件

[root@centos8 mysql]# mysqld --initialize --user=mysql --datadir=/data/mysql

准备启动脚本,并启动服务

[root@centos8 mysql]# cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos8 mysql]# chkconfig --add mysqld
[root@centos8 mysql]# service mysqld start

修改密码

[root@centos8 mysql]# grep password /data/mysql/mysql.log
2022-03-19T15:06:08.023287Z 1 [Note] A temporary password is generated for root@localhost: (dkJcVW1s8pS
[root@centos8 mysql]# mysqladmin -uroot -p'(dkJcVW1s8pS' password '123456'

安全初始化

[root@centos8 local]# mysql_secure_installation

测试登录

[root@centos8 mysql]# mysql -uroot -p123456
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 3
Server version: 5.7.36 Source distribution

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.

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

mysql>

3、二进制安装mariadb10.4
准备相关包

[root@centos8 ~]# yum -y install libaio numactl-libs libncurses

创建用户和组

[root@centos8 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql

创建目录并设置权限

[root@centos8 ~]# mkdir /data/mysql

[root@centos8 ~]# chown mysql:mysql /data/mysql

准备二进制文件包

[root@centos8 ~]# tar xf mariadb-10.4.24-linux-systemd-x86_64.tar.gz -C /usr/local/
[root@centos8 ~]# cd /usr/local
[root@centos8 local]# ln -sv mariadb-10.4.24-linux-systemd-x86_64 mysql
[root@centos8 local]# chown -R root:root /usr/local/mysql/

准备配置文件

[root@centos8 local]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock

添加PATH路径

[root@centos8 local]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos8 local]# . /etc/profile.d/mysql.sh

初始化数据库文件
注意:如果启动提示pid文件有问题,删除/data/mysql下文件重新初始化

[root@centos8 local]# ./mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[root@centos8 local]# ll /data/mysql/
total 122928
-rw-rw---- 1 mysql mysql    24576 Mar 20 10:42 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 Mar 20 10:42 aria_log_control
-rw-rw---- 1 mysql mysql      972 Mar 20 10:42 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12582912 Mar 20 10:42 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Mar 20 10:43 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Mar 20 10:42 ib_logfile1
-rw-rw---- 1 mysql mysql 12582912 Mar 20 10:43 ibtmp1
-rw-rw---- 1 mysql mysql        0 Mar 20 10:43 multi-master.info
drwx------ 2 mysql mysql     4096 Mar 20 10:42 mysql
-rw-rw---- 1 mysql mysql     2110 Mar 20 10:43 mysql.log
-rw-rw---- 1 mysql mysql        6 Mar 20 10:43 mysql.pid
srwxrwxrwx 1 mysql mysql        0 Mar 20 10:43 mysql.sock
-rw-r--r-- 1 root  root        15 Mar 20 10:42 mysql_upgrade_info
drwx------ 2 mysql mysql       20 Mar 20 10:42 performance_schema
drwx------ 2 mysql mysql       20 Mar 20 10:42 test

准备服务脚本,并启动服务

[root@centos8 local]# cp /usr/local/mysql/support-files/systemd/mariadb.service /usr/lib/systemd/system/
[root@centos8 local]# systemctl daemon-reload
[root@centos8 local]# systemctl start mariadb.service

安全初始化

[root@centos8 local]# mysql_secure_installation

测试登录

[root@centos8 local]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.24-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容