0
点赞
收藏
分享

微信扫一扫

第十周练习

1、通过编译、二进制安装MySQL5.7

二进制安装MySQL5.7

#安装相关包
[22:31:39 root@centos8 ~]#yum -y install libaio numactl-libs
#新增MySQL用户和组
[22:33:39 root@centos8 ~]#groupadd mysql
[22:34:11 root@centos8 ~]#useradd -r -g mysql -s /bin/false mysql
#准备程序文件
[22:36:46 root@centos8 ~]#tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local
22:37:31 root@centos8 ~]#cd /usr/local
[22:37:45 root@centos8 local]#ln -s mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[22:38:12 root@centos8 local]#chown -R root.root /usr/local/mysql
#准备环境变量
[22:38:41 root@centos8 local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[22:43:34 root@centos8 local]#. /etc/profile.d/mysql.sh
#准备配置文件
[23:01:17 root@centos8 ~]#cat /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
#生成随机密码
[23:02:10 root@centos8 ~]#mysqld --initialize --user=mysql --datadir=/data/mysql
[23:17:27 root@centos8 ~]#grep password /data/mysql/mysql.log
2022-05-22T15:06:11.949798Z 1 [Note] A temporary password is generated for root@localhost: p5fxM(ugrNJ#
#准备服务脚本和启动
[23:20:37 root@centos8 ~]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[23:25:40 root@centos8 ~]#chkconfig --add mysqld
[23:26:06 root@centos8 ~]#systemctl start mysqld
#修改口令
#修改前面生成的随机密码为指定密码
[23:26:35 root@centos8 ~]#mysqladmin -uroot -p'p5fxM(ugrNJ#' password XXX
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. #忽略警告
#测试登陆
[23:30:56 root@centos8 ~]#mysql -uroot -pXXX
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.33 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>

源码编码安装MySQL

#安装相关依赖包
[23:45:17 root@centos7 ~]#yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper
#准备用户和数据目录
[23:47:35 root@centos7 ~]#useradd -r -s /sbin/nologin -d /data/mysql mysql
#准备数据库目录
[23:48:06 root@centos7 ~]#mkdir /data/mysql
[23:50:35 root@centos7 ~]#chown mysql.mysql /data/mysql
#下载并解压源码包
[23:52:11 root@centos7 ~]#tar xvf mysql-5.6.51.tar.gz -C /usr/local/src
#源码编译安装MySQL
[23:54:24 root@centos7 mysql-5.6.51]#cd /usr/local/src/mysql-5.6.51/
[23:54:24 root@centos7 mysql-5.6.51]#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 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[00:08:08 root@centos7 mysql-5.6.51]#make install
#准备环境变量
[00:08:08 root@centos7 mysql-5.6.51]#echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[00:09:45 root@centos7 mysql-5.6.51]#. /etc/profile.d/mysql.sh
#生成数据库文件
[00:09:51 root@centos7 mysql-5.6.51]#cd /apps/mysql/
[00:10:22 root@centos7 mysql]#scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
#准备配置文件
[00:13:07 root@centos7 mysql]#cp -b /apps/mysql/support-files/my-default.cnf /etc/my.cnf
#准备启动简本,并启动MySQL
[00:13:16 root@centos7 mysql]#cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
[00:14:37 root@centos7 mysql]#chkconfig --add mysqld
[00:14:54 root@centos7 mysql]#systemctl start mysqld
#安全初始化
[00:16:21 root@centos7 mysql]#mysql_secure_installation
#测试登录
[00:16:36 root@centos7 mysql]#mysql -uroot -pXXX
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 13
Server version: 5.6.51 Source distribution

Copyright (c) 2000, 2021, 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>
举报

相关推荐

0 条评论