Centos7.3安装MySQL5.7

该安装是为CDH环境做准备,多了设置my.conf步骤,非CDH环境可以略过这一步。

Cloudera官网安装MySQL文档

1. 在线安装

1.查看并卸载系统自带的Mariad

rpm –qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.centos.x86_64


    
2.下载

网速不差可以选择在线安装  

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

3. 安装

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm


    
4. 升级(可不选)

sudo yum update

5. 安装mysql服务

sudo yum install mysql-server


6.启动服务

sudo systemctl start mysqld

7.先停止服务,备份和修改配置文件

sudo systemctl stop mysqld

cp /etc/my.cnf{,.bak}
vim /etc/my.cnf

**官方提供配置**

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
transaction-isolation = READ-COMMITTED
#Disabling symbolic-links is recommended to prevent assorted security risks;
#to do so, uncomment this line:
symbolic-links = 0
    
key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
    
max_connections = 550
#expire_logs_days = 10
#max_binlog_size = 100M
    
#log_bin should be on a disk with enough free space.
#Replace '/var/lib/mysql/mysql_binary_log' with an appropriate path for your
#system and chown the specified folder to the mysql user.
log_bin=/var/lib/mysql/mysql_binary_log
    
#In later versions of MySQL, if you enable the binary log and do not set
#a server_id, MySQL will not start. The server_id must be unique within
#the replicating group.
server_id=1
    
binlog_format = mixed
    
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
    
#InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit  = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
    
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
    
sql_mode=STRICT_ALL_TABLES

8.开启服务并设置开机启动

sudo systemctl start mysqld
sudo systemctl enable mysqld

9.初始化MySQL

sudo /usr/bin/mysql_secure_installation

这里如果出问题,是输入密码后提示权限问题,解决办法见:Centos7.3安装MySQL5.7.27问题
    
10.按提示输入

回车-Y-密码/确认密码 – Y – N – Y - Y

11.登录

mysql -uroot -p123456

12.MySQL远程访问授权

grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;

 

2. 离线安装(rpm)

MySQL官网下载

1.查看并卸载系统自带的Mariadb

rpm -qa | grep mysql
rpm –qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

2.上传以下rpm包到节点

mysql-community-client-5.7.27-1.el7.x86_64.rpm
mysql-community-common-5.7.27-1.el7.x86_64.rpm
mysql-community-libs-5.7.27-1.el7.x86_64.rpm
mysql-community-server-5.7.27-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm(这个CM安装需要)

3.安装

rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm
     
安装顺序
common -> libs -> client -> server -> libs-compat

如果提示缺少libaio依赖
yum install libaio

4.查看mysql服务状态

systemctl status mysqld

5.备份数据配置文件并修改

cp /etc/my.cnf{,.bak}

vim /etc/my.cnf

**官方提供配置**

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
transaction-isolation = READ-COMMITTED
#Disabling symbolic-links is recommended to prevent assorted security risks;
#to do so, uncomment this line:
symbolic-links = 0
    
key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
    
max_connections = 550
#expire_logs_days = 10
#max_binlog_size = 100M
    
#log_bin should be on a disk with enough free space.
#Replace '/var/lib/mysql/mysql_binary_log' with an appropriate path for your
#system and chown the specified folder to the mysql user.
log_bin=/var/lib/mysql/mysql_binary_log
    
#In later versions of MySQL, if you enable the binary log and do not set
#a server_id, MySQL will not start. The server_id must be unique within
#the replicating group.
server_id=1
    
binlog_format = mixed
    
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
    
#InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit  = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
    
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
    
sql_mode=STRICT_ALL_TABLES

6.开启服务及开机启动

sudo systemctl start mysqld
sudo systemctl enable mysqld

7.获取初始密码

grep 'temporary password' /var/log/mysqld.log

这里如果出问题,是mysqld.log文件为空解决办法见:Centos7.3安装MySQL5.7.27问题

8.登录MySQL

mysql -uroot -pxxx

9.修改密码

set password for 'root'@'localhost' = password('123456')

10.MySQL远程访问授权

grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

訾零

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值