MySQL5.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 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小时售前售后,随时帮您解答问题的。
网页题目:MySQL5.7部署分类
转载注明:http://scyanting.com/article/iheseo.html