文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

mysql5.7_sourcecode_install_on OEL7.2_managed by systemd

2024-04-02 19:55

关注

1   描述

OEL7.2 x64默认使用最小化安装。 在此基础上安装mysql 5.7.22 source code.

(mysql-8.0.11 cmake要用的版本至少为2.8.12,而OEL7.2 cmake版本为2.8.11,如需用光盘中的cmake,需要升级系统版本)

mysql服务启动关闭由systemd来管理,编译时启用参数-DWITH_SYSTEMD=1

2   操作环境

2.1  OS info

OEL7.2 x64

2.2  Other

必备软件包:

cmake

make

gcc-c++

boost(You can download it when execute cmake with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>  , or download it from   https://sourceforge.net/projects/boost/files/boost/1.59.0/ )

ncurses-devel

perl

bison

3   过程设计

shell>yum -q -y install cmake make gcc-c++ ncurses-devel perl bison

# Preconfiguration setup

shell> groupadd mysql

shell> useradd -r -g mysql -s /bin/false mysql

# Beginning of source-build specific instructions

shell> tar zxvf mysql-VERSION.tar.gz

shell> cd mysql-VERSION

shell> mkdir bld

shell> cd bld

##### shell> cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/

##### shell> cmake .. -DWITH_BOOST=/usr/local/boost_1_59_0

shell> cmake .. -DWITH_BOOST=/usr/local/boost_1_59_0 -DWITH_SYSTEMD=1

shell> make -j 4

shell> make install

# End of source-build specific instructions

# Postinstallation setup

shell> cd /usr/local/mysql

shell> bin/mysqld --initialize --user=mysql

##### shell> bin/mysql_install_db --user=mysql --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql/data

shell> cp /usr/local/mysql/usr/lib/systemd/system/mysqld* /usr/lib/systemd/system/

shell>systemctl daemon-reload

shell>systemctl enable mysqld.service

shell>mkdir /var/run/mysqld/

shell>chown mysql:mysql /var/run/mysqld/

shell>systemctl restart mysqld.service

4   详细步骤操作

shell> cmake .. -DWITH_BOOST=/usr/local/boost_1_59_0 -DWITH_SYSTEMD=1

安装编译过程略

# Postinstallation setup

[root@localhost bld]# cd /usr/local/mysql/

[root@localhost mysql]# bin/mysqld --initialize --user=mysql

2018-05-02T19:06:52.849013Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-05-02T19:06:56.156730Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-05-02T19:06:56.428913Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-05-02T19:06:56.531465Z 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: fb8f5e7d-4e3b-11e8-bd58-000c29a3197b.

2018-05-02T19:06:56.540768Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-05-02T19:06:56.542462Z 1 [Note] A temporary password is generated for root@localhost: 4E-d,-hnvhtk

[root@localhost mysql]# bin/mysql -uroot -p

Enter password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

[root@localhost mysql]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld* /usr/lib/systemd/system/

[root@localhost mysql]# systemctl daemon-reload

[root@localhost mysql]# systemctl enable mysqld.service

Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

[root@localhost mysql]# mkdir /var/run/mysqld/

[root@localhost mysql]# chown -R mysql /var/run/mysqld/

[root@localhost mysql]# systemctl restart mysqld.service

[root@localhost mysql]# bin/mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

Query OK, 0 rows affected (0.00 sec)

 

mysql> exit

Bye

[root@localhost mysql]# ps -ef |grep mysql

mysql     21993      1  0 03:10 ?        00:00:00 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

root      22024   2427  0 03:14 pts/0    00:00:00 grep --color=auto mysql

[root@localhost mysql]# systemctl stop mysqld.service

5   个人总结

a.make -j

-j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg. 

我没有在-j后面加数字限制job数。结果编译两次都导致系统报outofmemory错误。数值与cpu个数等值效果最好。

b.cmake编译时可选的参数,请参考https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

c. 如系统已经连接外网,boost可以在cmake的时候打开下载参数-DDOWNLOAD_BOOST=1

d.systemd调用文件

cmake时启用了systemd参数 -DWITH_SYSTEMD=1 , 则会生成相应的可以由systemd调用的mysqld.service文件。文件内容如下:

[root@localhost system]# ls /usr/local/mysql/usr/lib/systemd/system/

mysqld.service  mysqld@.service

[root@localhost system]# grep -v ^# mysqld.service |grep -v ^$

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

Type=forking

PIDFile=/var/run/mysqld/mysqld.pid

TimeoutSec=0

PermissionsStartOnly=true

ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd

ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

EnvironmentFile=-/etc/sysconfig/mysql

LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

[root@localhost system]# grep -v ^# mysqld@.service |grep -v ^$

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

Type=forking

PIDFile=/var/run/mysqld/mysqld-%i.pid

TimeoutSec=0

PermissionsStartOnly=true

ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd %I

ExecStart=/usr/local/mysql/bin/mysqld --defaults-group-suffix=@%I --daemonize --pid-file=/var/run/mysqld/mysqld-%i.pid $MYSQLD_OPTS

EnvironmentFile=-/etc/sysconfig/mysql

LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

[root@localhost system]#

 

将mysqld.service 与mysqld@.service copy到操作系统/usr/lib/systemd/system/目录中,然后reload daemon。

注意pid-file的目录/var/run/mysqld/需要存在且目录权限为mysql,否则会启动报错。系统重启后/var/run/mysqld目录会自动消失,建议将pid-file文件放置在mysql用户长久目录下。

6   资料参考引用

https://dev.mysql.com/doc/refman/5.7/en/source-installation.html

https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯