首页 > 科技 > 在centos上以二进制方式安装mysql5.7数据库

在centos上以二进制方式安装mysql5.7数据库

现在mysql在互联网领域非常流行,甚至传统的金融,证券,银行也在将核心数据库从db2,oracle逐渐转换成mysql数据库,从DB-Engines排行榜上,可以看到在2019年12月mysql已经跃居到第二。

DB-Engines 排名是按人气排名数据库管理系统,涵盖 340 多个系统。 排名标准包括搜索系统名称时搜索引擎结果的数量、Google 趋势、 Stack Overflow 网站、LinkedIn、Twitter 等社交网络中的提及的情况, 综合比较、排名。该排名每月更新一次,此排行榜非常具有权威性。


对于程序员或者初级DBA掌握mysql数据库,都是非常必要,和有价值的技能。首先从mysql数据库安装开始。

MySQL安装方式

mysql有3种安装方式,分别为RPM包安装,二进制包安装,源码安装。其中RPM包安装最方便,源码安装最耗时和最麻烦,二进制包安装居中。如果你一台服务器上要安装两种版本的mysql数据库,建议使用二进制包去安装,今天给大家介绍在在centos上以二进制方式安装mysql5.7数据库。

首先从官网去下载二进制包


在这里一定要选择Linux-Generic,不要选错了,然后就可以正常进行下载,要在linux环境下载,可以通过wget方式,这里就不再介绍了。

依赖包安装

mysql数据库依赖libaio库,如果centos系统没有安装,就需要先按照libaio,可以先检查是否已经安装

[root@localhost soft]# rpm -qa|grep -i libaiolibaio-0.3.109-13.el7.x86_64

这里我的centos系统已经安装,如果检查出来结果为空,则用yum进行安装

[root@localhost soft]# yum install libaio*

创建数据库用户和用户组

在这里最好指定mysql的组ID和mysql用户的ID,这样在后期规模化运维时能省很多事情。

[root@localhost soft]#groupadd -g 4001 mysql[root@localhost soft]#useradd -r -g mysql -u 2001 -s /bin/false mysql 

创建目录

mkdir -p /data/mysql/{data,log,conf,run}chown -R mysql:mysql /data/mysqlchmod 750 /data/mysql/{data,log,conf,run}

初始化数据库

mysqld --initialize --user=mysql --basedir=/data/mysql/ --datadir=/data/mysql/data
如果要启用SSL安全连接,执行如下命令
mysql_ssl_rsa_setup --basedir=/data/mysql --datadir=/data/mysql/data/

配置参数文件

[mysqld]port = 3306socket = /data/mysql/run/mysql.sockpid_file = /data/mysql/run/mysql.piddatadir = /data/mysql/datadefault_storage_engine = InnoDBmax_allowed_packet = 128Mmax_connections = 1000open_files_limit = 65535skip-name-resolvelower_case_table_names=1character-set-server = utf8mb4collation-server = utf8mb4_unicode_ciinit_connect='SET NAMES utf8mb4'innodb_buffer_pool_size = 128Minnodb_log_file_size = 128Minnodb_file_per_table = 1innodb_flush_log_at_trx_commit = 1key_buffer_size = 16Mlog-error = /data/mysql/log/error.loglog-bin = /data/mysql/log/mysql_bin.logslow_query_log = 1slow_query_log_file = /data/mysql/log/mysql_slow_query.loglong_query_time = 10tmp_table_size = 16Mmax_heap_table_size = 16Mserver-id=3306[client]port = 3306socket = /data/mysql/run/mysql.sock

启停mysql实例

mysqld_safe --defaults-file=/data/mysql/conf/my.cnf &
mysqladmin --socket=/data/mysql/run/mysql.sock shutdown &

安全设置

在这一步,可以设置root用户的密码安全策略,删除匿名用户,test数据库,对数据库进行安全加固,非常实用的一个功能

[mysql@localhost run]$ mysql_secure_installation --socket=/data/mysql/run/mysql.sockSecuring the MySQL server deployment.Enter password for user root: The existing password for the user account root has expired. Please set a new password.New password: Re-enter new password: VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other key for No: NoUsing existing password for root.Change the password for root ? ((Press y|Y for Yes, any other key for No) : No ... skipping.By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : YSuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : YSuccess.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database...Success. - Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : YSuccess.

导入时区

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql --socket=/data/mysql/run/mysql.sock -uroot -proot1234 mysql

本文来自投稿,不代表本人立场,如若转载,请注明出处:http://www.sosokankan.com/article/1960871.html

setTimeout(function () { fetch('http://www.sosokankan.com/stat/article.html?articleId=' + MIP.getData('articleId')) .then(function () { }) }, 3 * 1000)