Linux学习 第十周
1. 二进制安装MySQL5.7
Mysql5.7下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
创建mysql用户和组
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -g mysql -s /sbin/nologin -r mysql
创建数据目录并授权
[root@localhost ~]# mkdir -p /data/mysql [root@localhost ~]# chown mysql:mysql /data/mysql/
解压二进制目录,创建配置文件并对数据库进行初始化
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local [root@localhost ~]# cd /usr/local/ [root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql [root@localhost local]# chown -R mysql:mysql mysql [root@localhost local]# vim /etc/my.cnf [client] port = 3306 socket = /data/mysql/mysql.sock [mysqld] port = 3306 socket = /data/mysql/mysql.sock user = mysql basedir = /usr/local/mysql datadir = /data/mysql [root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql 2022-03-11T14:38:53.751932Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-03-11T14:38:53.960341Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-03-11T14:38:53.995089Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-03-11T14:38:54.065606Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f9b394f3-a148-11ec-ab38-000c29ac5864. 2022-03-11T14:38:54.066793Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-03-11T14:38:54.427402Z 0 [Warning] CA certificate ca.pem is self signed. 2022-03-11T14:38:54.549650Z 1 [Note] A temporary password is generated for root@localhost: ,lIslC6aog(E #,lIslC6aog(E为root@localhost第一次登录的随机密码
添加mysql环境变量
[root@localhost local]# echo "export PATH=$PATH:/usr/src/mysql/bin" >> /etc/profile [root@localhost local]# . /etc/profile
准备服务脚本,并启动服务
[root@localhost local]# mv /etc/init.d/mysql /etc/init.d/mysqld [root@localhost local]# chkconfig --add mysqld [root@localhost local]# service mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. SUCCESS! [root@localhost local]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 80 :::3306 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::*
[root@localhost ~]# mysql -uroot -p,lIslC6aog\(E 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 2 Server version: 5.7.33 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>
2. 编译安装mysql5.7
mysql5.7源码下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
准备用户和数据目录
[root@localhost ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql [root@localhost ~]# mkdir /data/mysql [root@localhost ~]# chown mysql.mysql /data/mysql
安装相关依赖包并解压
[root@localhost ~]# 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 libe
[root@localhost ~]# tar xvf mysql-5.7.29-el7-x86_64.tar.gz -C /usr/local/src
源码编译安装 MySQL
[root@localhost ~]# tar xvf mysql-5.7.37.tar.gz -C /usr/local/src [root@localhost mysql-5.7.37]# cd /usr/local/src/mysql-5.7.37/ [root@localhost mysql-5.7.37]# 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 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/root/mysql-5.7.22/boost/boost_1_59_0
[root@localhost mysql-5.7.37]# make && make install
cmake时报错
CMake Error at cmake/boost.cmake:88 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory> This CMake script will look for boost in <directory>. If it is not there, it will download and unpack it (in that directory) for you. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 Call Stack (most recent call first): cmake/boost.cmake:276 (COULD_NOT_FIND_BOOST) CMakeLists.txt:536 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/usr/local/src/mysql-5.7.37/CMakeFiles/CMakeOutput.log". See also "/usr/local/src/mysql-5.7.37/CMakeFiles/CMakeError.log".
解决方法:
用find找到文件 boost_1_59_0
在cmake时添加:
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=<boost_1_59_0文件路径>
添加环境变量
[root@localhost mysql-5.7.22]# echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@localhost mysql-5.7.22]# . /etc/profile.d/mysql.shs
生成数据文件
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/apps/data
2022-03-11T16:38:02.745537Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-03-11T16:38:02.985167Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-03-11T16:38:03.018946Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-03-11T16:38:03.083448Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9ed9228d-a159-11ec-8464-000c29f5b49d.
2022-03-11T16:38:03.084671Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-03-11T16:38:03.085722Z 1 [Note] A temporary password is generated for root@localhost: +-gXAf721Toj
[root@localhost ~]# vi /etc/my.cnf [mysqld] datadir=/apps/data/mysql #socket=/apps/mysql/mysql/mysql.sock datadir=/data/mysql [mysqld_safe] # # include all files from the config directory # !includedir /etc/my.cnf.d
准备启动脚本,并启动服务
[root@localhost ~]# cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# chkconfig --add mysqld [root@localhost ~]# service mysqld start
连接数据库
[root@localhost ~]# mysql -uroot -p+-gXAf721Toj 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.22 Copyright (c) 2000, 2018, 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>
3. 二进制安装mariadb10.4
mariadb二进制包下载地址:https://mariadb.org/download/?t=mariadb&p=mariadb&r=10.4.24
创建mysql用户和组,相关目录
[root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -g mysql -r -s /sbin/nologin mysql [root@localhost ~]# mkdir -p /data/mysql/ [root@localhost ~]# chown mysql.mysql /data/mysql/ [root@localhost ~]# ll /data/mysql
解压mariadb的tar包
[root@localhost ~]# tar zxvf mariadb-10.4.24-linux-systemd-x86_64.tar.gz -C /usr/local/src/ [root@localhost ~]# cd /usr/local/ [root@localhost local]# ln -s src/mariadb-10.4.24-linux-systemd-x86_64 mysql
初始化相关数据
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld.server [root@localhost mysql]# chkconfig --add mysqld.server [root@localhost mysql]# service mysqld.server start Starting mysqld.server (via systemctl): [ OK ] [root@localhost bin]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
登录数据库
[root@localhost ~]# mysql -uroot -p Enter password: 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)]>

浙公网安备 33010602011771号