千家信息网

MySQL 5.7部署分类

发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,本文主要给大家介绍MySQL 5.7部署分类,其所涉及的东西,从理论知识来获悉,有很多书籍、文献可供大家参考,从现实意义来讲,累计多年的实践经验可分享给大家。MySQL5.7部署可以分为rpm包部署、
千家信息网最后更新 2025年01月22日MySQL 5.7部署分类

本文主要给大家介绍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数据库运行的用户和用户组

groupadd -r mysqluseradd -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/data2019-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=457902019-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/dataGenerating 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 onchkconfig --list mysqldNote: 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=utf8datadir=/application/mysql/datasocket=/application/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-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=utf8socket=/application/mysql/mysql.sock[mysql]character-set-server=utf8socket=/application/mysql/mysql.sock

6.启动mysql
启动mysql

/etc/init.d/mysqld start

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

# mysql -uroot -pEnter 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 wrapperConnection id:      4Current database:   Current user:       root@localhostSSL:            Not in useCurrent pager:      stdoutUsing outfile:      ''Using delimiter:    ;Server version:     5.7.26 MySQL Community Server (GPL)Protocol version:   10Connection:     Localhost via UNIX socketServer characterset:    utf8Db     characterset:    utf8Client characterset:    utf8Conn.  characterset:    utf8UNIX socket:        /application/mysql/mysql.sockUptime:         7 min 56 secThreads: 2  Questions: 14  Slow queries: 0  Opens: 116  Flush tables: 1  Open tables: 109  Queries per second avg: 0.029
--------------

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