Linux学习 第十周
1. 二进制安装MySQL5.7
Mysql5.7下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
创建mysql用户和组
1 2 | [root@localhost ~] # groupadd mysql [root@localhost ~] # useradd -g mysql -s /sbin/nologin -r mysql |
创建数据目录并授权
1 2 | [root@localhost ~] # mkdir -p /data/mysql [root@localhost ~] # chown mysql:mysql /data/mysql/ |
解压二进制目录,创建配置文件并对数据库进行初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [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环境变量
1 2 | [root@localhost local ] # echo "export PATH=$PATH:/usr/src/mysql/bin" >> /etc/profile [root@localhost local ] # . /etc/profile |
准备服务脚本,并启动服务
1 2 3 4 5 6 7 8 9 10 11 12 | [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 :::* |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [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
准备用户和数据目录
1 2 3 | [root@localhost ~] # useradd -r -s /sbin/nologin -d /data/mysql mysql [root@localhost ~] # mkdir /data/mysql [root@localhost ~] # chown mysql.mysql /data/mysql |
安装相关依赖包并解压
1 | [root@localhost ~] # yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel \<br>gnutls-devel libxml2-devel openssl-devel libe<br>[root@localhost ~]# tar xvf mysql-5.7.29-el7-x86_64.tar.gz -C /usr/local/src<br> |
源码编译安装 MySQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [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 \<br>-DDEFAULT_COLLATION=utf8_general_ci \<br>-DDOWNLOAD_BOOST=1 \<br>-DWITH_BOOST= /root/mysql-5 .7.22 /boost/boost_1_59_0 [root@localhost mysql-5.7.37] # make && make install |
cmake时报错
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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文件路径>
添加环境变量
1 2 | [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 |
生成数据文件
1 2 3 4 5 6 7 8 9 10 11 12 | [root@localhost ~] # mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/apps/data<br>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).<br>2022-03-11T16:38:02.985167Z 0 [Warning] InnoDB: New log files created, LSN=45790<br>2022-03-11T16:38:03.018946Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.<br><em id="__mceDel" style="font-size: 13px; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel">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.<br></em></em></em></em><em id="__mceDel" style="font-size: 13px; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel">2022-03-11T16:38:03.084671Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.<br></em></em></em></em></em><em id="__mceDel" style="font-size: 13px; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel">2022-03-11T16:38:03.085722Z 1 [Note] A temporary password is generated for root@localhost: +-gXAf721Toj</em></em></em></em></em></em>[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 |
准备启动脚本,并启动服务
1 2 3 | [root@localhost ~] # cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~] # chkconfig --add mysqld [root@localhost ~] # service mysqld start |
连接数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [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用户和组,相关目录
1 2 3 4 5 | [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包
1 2 3 | [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 |
初始化相关数据
1 2 3 4 5 6 | [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 |
登录数据库
1 2 3 4 5 6 7 8 9 10 11 | [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)]> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~