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小时售前售后,随时帮您解答问题的。

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...