MySQL 5.7部署分类
admin
2023-04-17 02:01:25
0

本文主要给大家介绍MySQL 5.7部署分类,其所涉及的东西,从理论知识来获悉,有很多书籍、文献可供大家参考,从现实意义来讲,累计多年的实践经验可分享给大家。                                                    

MySQL5.7部署可以分为rpm包部署、源码包部署、二进制包部署。

源码包部署:优点是灵活性较高,可以自定义编译参数,效率高,缺点是部署时间较长
二进制包部署:优点是事先已经编译好,部署较快,可以自定义一部分参数,缺点是时间相比使用yum安装,还是较长
rpm包部署:优点是部署速度快,缺点是定制性差
一般没有特殊要求时,可以使用yum包部署
下面开始使用二进制包部署MySQL5.7.26二进制包
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
在Select Operating System选项中选中”Linux Generic",在最下方的Linux - Generic (glibc 2.12) (x86, 64-bit), TAR项后方的download即可下载
1.添加MySQL数据库运行的用户和用户组

MySQL 5.7部署分类

groupadd -r mysql
useradd -r -g mysql mysql

2.此次MySQL部署的目录为/application,将MySQL安装包解压到/application/mysql-5.7.26-linux-glibc2.12-x86_64目录,并为此目录创建软链接

 ln -s /application/mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql

更改目录权限
chown -R mysql:mysql /application/mysql-5.7.26-linux-glibc2.12-x86_64
3.初始化数据库

/application/mysql-5.7.26-linux-glibc2.12-x86_64/bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data

[root@chanye application]# /application/mysql-5.7.26-linux-glibc2.12-x86_64/bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
2019-06-18T08:35:49.103727Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-18T08:35:49.885283Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-18T08:35:49.944856Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-18T08:35:50.002905Z 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: 138aa81a-91a4-11e9-8f49-005056813525.
2019-06-18T08:35:50.004044Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-18T08:35:50.004493Z 1 [Note] A temporary password is generated for root@localhost: O;iSA6z>SieK

记住最后一行的临时密码
4.创建RSA  private key

/application/mysql/bin/mysql_ssl_rsa_setup --datadir=/application/mysql/data
Generating a 2048 bit RSA private key
..........................................................................................+++
....+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
............................+++
.+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..........................................................................+++
...........................................................................................+++
writing new private key to 'client-key.pem'

5.添加mysql到开机自启动

cp /application/mysql-5.7.26-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld

修改/etc/init.d/mysqld中的basedir和datadir

46 basedir=/application/mysql
 47 datadir=/application/mysql/data

加入开机自启动

chkconfig mysqld on
chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

修改全局配置文件将mysql可执行路径加入到PATH,在/etc/profile最后一行添加:

export PATH=/application/mysql/bin:$PATH

使用source /etc/profile使配置生效
删掉系统自带的/etc/my.cnf或者改名,在/application/mysql/目录新建my.cnf,并且将文件属性调整为mysql:mysql

[mysqld]
character-set-server=utf8
datadir=/application/mysql/data
socket=/application/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[client]
character-set-server=utf8
socket=/application/mysql/mysql.sock

[mysql]
character-set-server=utf8
socket=/application/mysql/mysql.sock

6.启动mysql
启动mysql

/etc/init.d/mysqld start

此时使用初始化提供的密码进行登陆

# mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

系统默认的客户端使用的mysql.sock文件是基于unix sock的,此时最简便的办法是创建一个软链接

ln -s /application/mysql/mysql.sock /tmp/mysql.sock

如果不创建软链接,使用mysql命令登陆的时候使用-S选项,手工指定mysql.sock的位置也是可以登陆的
登陆成功后需要更改管理员密码

alter user 'root'@'localhost' identified by '598545$kdOctamvsU';
flush privileges;

查看mysql状态

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:      4
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.26 MySQL Community Server (GPL)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /application/mysql/mysql.sock
Uptime:         7 min 56 sec

Threads: 2  Questions: 14  Slow queries: 0  Opens: 116  Flush tables: 1  Open tables: 109  Queries per second avg: 0.029

--------------

看了以上介绍MySQL 5.7部署分类,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,大家可以继续关注行业资讯板块,会定期给大家更新行业新闻和知识,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。

相关内容

热门资讯

徐巧芯剖析赖清德:最怕自己丢掉... 海峡导报综合报道 大罢免投票一周年纪念活动26日举行,台北市长蒋万安出席并怒轰,民进党一年过后仍没有...
中国红十字会总会紧急向广东调拨... 记者从中国红十字会总会了解到,针对台风“红霞”给广东造成的灾情,中国红十字会总会启动四级应急响应,紧...
这些少年,正被“毒蛋”围猎 李梦抽了几口电子烟,吐出了白色的烟雾,有一股浓烈的水果香味。随后,她看着自己握电子烟的手,跟身边人说...
蒋万安号召“倒阁”,卢秀燕认为... 海峡导报综合报道 台北市长蒋万安27日抛出震撼议题,表示多名民代向他提议推动“倒阁”,要求台行政机构...
特朗普将在白宫会见两位重要客人 俄乌战争仍未结束,美伊冲突又有升级风险。在此背景下,美国总统特朗普将在白宫接见乌克兰和以色列领导人。...
新租客打扫卧室柜子上掉落4万元... 近日,莲前西路某小区内,张倩签下一套房子的租赁合同。当天上午,她带着12岁的大女儿周馨怡和11岁的小...
六部门通告:禁止涉军队退役报废... 关于禁止涉军队退役报废装备销售活动的通告近年来,部分经营者在线上线下公开销售涉及我军退役报废装备(指...
九寨沟景区发生泥石流,部分道路... 7月26日,九寨沟风景名胜区管理局发布泥石流灾害通报:2026年7月26日15时50分,九寨沟景区局...
空调26度不凉是什么原因 从空调内部元器件来说,不凉的原因有可能是温度传感器出现故障了,也有可能是空调压缩机或者铜管出现问题,...
鲸鸿动能携手香港国际机场、鸿蒙...   2026 年 7 月 25 日,十余位鸿蒙车主组成的车队从珠海出发,经港珠澳大桥通关抵达香港国际...