centos rpm mysql 安装_CentOS RPM 安装 MySQL5.7

环境

CentOS 7 64位

MySQL 5.7 64位

1.卸载系统自带的 mariadb

[root@localhost /]# rpm -qa|grep mariadb

mariadb-libs-5.5.56-2.el7.x86_64

[root@localhost /]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

2.下载RPM包

到MySQL官网下载rpm集合包到本地再上传至服务器或通过下面的方法直接在服务器下载

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar

3.解压tar包

[root@localhost softwares]# ls

mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

[root@localhost softwares]# tar -xvf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar

mysql-community-server-5.7.18-1.el7.x86_64.rpm

mysql-community-embedded-devel-5.7.18-1.el7.x86_64.rpm

mysql-community-devel-5.7.18-1.el7.x86_64.rpm

mysql-community-client-5.7.18-1.el7.x86_64.rpm

mysql-community-common-5.7.18-1.el7.x86_64.rpm

mysql-community-embedded-5.7.18-1.el7.x86_64.rpm

mysql-community-embedded-compat-5.7.18-1.el7.x86_64.rpm

mysql-community-libs-5.7.18-1.el7.x86_64.rpm

mysql-community-server-minimal-5.7.18-1.el7.x86_64.rpm

mysql-community-test-5.7.18-1.el7.x86_64.rpm

mysql-community-minimal-debuginfo-5.7.18-1.el7.x86_64.rpm

mysql-community-libs-compat-5.7.18-1.el7.x86_64.rpm

4.安装

依次执行(几个包有依赖关系,所以执行有先后)下面命令安装

rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

5.数据库初始化

mysqld --initialize --user=mysql

--initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期(密码在/var/log/mysqld.log中),登陆后你需要设置一个新的密码,而使用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码。

[root@localhost softwares]# more /var/log/mysqld.log

2018-02-24T08:27:17.789803Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2018-02-24T08:27:18.923811Z 0 [Warning] InnoDB: New log files created, LSN=45790

2018-02-24T08:27:18.981104Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2018-02-24T08:27:19.116973Z 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: 87296646-193c-11e8-adaf-000c29ee8fae.

2018-02-24T08:27:19.332937Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2018-02-24T08:27:19.333647Z 1 [Note] A temporary password is generated for root@localhost: m)6_=8yl6(pA

最后一行给出了MySQL登录密码。

启动MySQL服务,登录MySQL

[root@localhost softwares]# systemctl start mysqld

[root@localhost softwares]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.18

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

6.重置root用户密码

提示密码过期,需要重置

mysql> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

重置密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

mysql> set password for 'root'@'localhost'=password('new_password');

7.远程授权登录

root 用户名

% 所有人都可以访问

password 密码

# 给特定IP授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY 'password' WITH GRANT OPTION;

# 给任意IP授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

刷新权限

flush privileges;

打开3306端口

firewall-cmd --add-port=3306/tcp --permanent

重启防火墙

systemctl restart firewalld

8.配置utf8编码

修改/etc/my.cnf,在后面加上下面内容

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'

重启MySQL

systemctl restart mysqld

显示编码

show variables like '%character%';

常见错误

[root@VM_107_38_centos tools]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

warning: mysql-community-server-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

error: Failed dependencies:

libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.18-1.el7.x86_64

libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.18-1.el7.x86_64

libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.18-1.el7.x86_64

解决办法:

yum install libnuma*

错误:依赖检测失败:

perl(Getopt::Long) 被 mysql-community-server-5.7.18-1.el7.x86_64 需要

perl(strict) 被 mysql-community-server-5.7.18-1.el7.x86_64 需要

解决办法:

yum install perl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值