CentOS 6.5 npm安装 mysql 5.7.24

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/guopengNo1/article/details/89208049

CentOS  7.0以上 需要先卸载mariadb

#rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

CentOS  6.5 跳过此步骤

[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@localhost ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps

提前下载好安装包,或者wget下载

下载地址:https://downloads.mysql.com/archives/community/

打开网址后

Product Version 选择 5.7 最新的小版本,本文选择的是5.7.24

Operation System:选择Red Hat Enterprise Linux / Oracle Linux 

OS Version:选择 Red Hat Enterprise Linux6 / Oracle Linux (x86, 64-bit)

在下方列表中选择红框中进行下载,官方下载比较慢,可以找其他渠道下载,一定要下载匹配的版本。

下载完成后上传至服务器。

mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar

安装所需要的依赖包

[root@localhost ~]# yum install libaio
[root@localhost ~]# yum install net-tools
[root@localhost ~]# yum install numactl

解压文件

[root@localhost home]# tar -xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar 
mysql-community-test-5.7.24-1.el6.x86_64.rpm
mysql-community-client-5.7.24-1.el6.x86_64.rpm
mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
mysql-community-libs-5.7.24-1.el6.x86_64.rpm
mysql-community-server-5.7.24-1.el6.x86_64.rpm
mysql-community-devel-5.7.24-1.el6.x86_64.rpm
mysql-community-embedded-5.7.24-1.el6.x86_64.rpm
mysql-community-embedded-devel-5.7.24-1.el6.x86_64.rpm
mysql-community-common-5.7.24-1.el6.x86_64.rpm
[root@localhost home]# ll
总用量 929184
-rw-r--r-- 1 root root  475740160 4月  11 14:30 mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  23850816 10月  5 2018 mysql-community-client-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415    340192 10月  5 2018 mysql-community-common-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415   3798252 10月  5 2018 mysql-community-devel-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415  39475132 10月  5 2018 mysql-community-embedded-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 137599268 10月  5 2018 mysql-community-embedded-devel-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415   2203052 10月  5 2018 mysql-community-libs-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415   1723740 10月  5 2018 mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 160619544 10月  5 2018 mysql-community-server-5.7.24-1.el6.x86_64.rpm
-rw-r--r-- 1 7155 31415 106117992 10月  5 2018 mysql-community-test-5.7.24-1.el6.x86_64.rpm
[root@localhost home]# 

安装mysql-server服务,只需要安装如下4个软件包即可,使用rpm -ivh进行安装(按顺序安装,后面的服务依赖前面的服务)

[root@localhost home]# rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm 
[root@localhost home]# rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
[root@localhost home]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm 
[root@localhost home]# rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm

遇到如下错误解决方案:

  1. mysql依赖错误
  2. 缺少依赖包 net-tools
  3. 缺少依赖包 libaio
  4. 缺少依赖包 numactl

原因:mysql依赖错误
解决:清除yum里所有mysql依赖包
删除后,从第一个rpm包重新开始安装


[root@localhost home]# rpm -ivh mysql-community-libs-5.7.24-1.el6.x86_64.rpm 
warning: mysql-community-libs-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.24-1.el6.x86_64


root@localhost home]# rpm -qa|grep mysql
[root@localhost home]# yum remove mysql-libs


[root@localhost home]# rpm -ivh mysql-community-common-5.7.24-1.el6.x86_64.rpm 
warning: mysql-community-common-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-common ########################################### [100%]
原因:缺少依赖包 net-tools
解决:安装依赖

[root@localhost home]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
	net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要


[root@localhost home]# yum install net-tools
原因:缺少依赖包 libaio
解决:安装依赖

[root@localhost home]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.17-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
	libaio.so.1()(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
	libaio.so.1(LIBAIO_0.1)(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
	libaio.so.1(LIBAIO_0.4)(64bit) 被 mysql-community-server-5.7.17-1.el7.x86_64 需要
	net-tools 被 mysql-community-server-5.7.17-1.el7.x86_64 需要


[root@localhost home]# yum install libaio
错误原因:缺失依赖包 numactl
解决方案:安装依赖

[root@localhost home]# rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm 
warning: mysql-community-server-5.7.24-1.el6.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.24-1.el6.x86_64
	libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
	libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64


[root@localhost home]# yum install numactl
为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化
mysqld --initialize --user=mysql
如果是以 mysql 身份运行,则可以去掉 --user 选项。

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

这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里,日志最后的就是自动生成的密码

[root@localhost home]# mysqld --initialize --user=mysql
[root@localhost home]# cat /var/log/mysqld.log 
2019-04-11T08:47:56.719826Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-11T08:47:57.051611Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-11T08:47:57.122064Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-11T08:47:57.137970Z 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: 80dba90f-5c36-11e9-8674-0050569f3b52.
2019-04-11T08:47:57.139932Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-11T08:47:57.140929Z 1 [Note] A temporary password is generated for root@localhost: w71abh%H4o1w
启动mysql服务:

CentOS  6 和 CentOS 7 启动命令不太一样:

CentOS  6 没有 systemctl命令,使用service启动

1、原来的 service 命令与 systemctl 命令对比
daemon命令    systemctl命令    说明
service [服务] start    systemctl start [unit type]    启动服务
service [服务] stop    systemctl stop [unit type]    停止服务
service [服务] restart    systemctl restart [unit type]    重启服务

CentOS 6
[root@localhost home]# service mysqld start    ###启动命令
正在启动 mysqld:                                          [确定]
[root@localhost home]# service mysqld status   ###查看状态
mysqld (pid  15136) 正在运行...
[root@localhost home]# service mysqld stop     ###停止命令


CentOS 7 
[root@localhost home]# systemctl start mysqld.service  ###启动命令
[root@localhost home]# systemctl status mysqld.service ###查看状态
[root@localhost home]# systemctl stop mysqld.service   ###关闭mysql

查看命令和查看端口

[root@localhost home]# ps -ef|grep mysql
root     15266     1  0 17:13 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql    15472 15266  0 17:13 pts/0    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root     15507 14668  0 17:19 pts/0    00:00:00 grep mysql
[root@localhost home]# 
[root@localhost home]# 
[root@localhost home]# 
[root@localhost home]# netstat -anop|grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      15472/mysqld        off (0.00/0/0)
[root@localhost home]# 

准备登录,

由于MySQL5.7.4之前的版本中默认是没有密码的,登录后直接回车就可以进入数据库,进而进行设置密码等操作。其后版本对密码等安全相关操作进行了一些改变,在安装过程中,会在安装日志中生成一个临时密码。使用下面命令找到这个临时密码。

[root@localhost home]# grep 'temporary password' /var/log/mysqld.log
2019-04-11T08:47:57.140929Z 1 [Note] A temporary password is generated for root@localhost: w71abh%H4o1w

w71abh%H4o1w 为临时密码。

登录mysql

[root@localhost home]# mysql -uroot -p
Enter password:       ##################这里粘贴刚才的临时密码##############
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24

Copyright (c) 2000, 2018, 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> 

如果不修改密码的话是没办法就行操作的,见下面提示,所以需要修改密码,如下命令:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password('12345678');                   ##########需要输入复杂的密码
或者
mysql> alter user root@localhost identified by '12345678';  ##########需要输入复杂的密码

Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> 

-------------------------------------------------------------------------------------------
在5.6后,mysql内置密码增强机制,低强度密码会报错:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

修改方案见此文章:安装MySQL报错 : Your password does not satisfy the current policy requirements

使用两种方式登录后可操作:

[root@localhost home]# mysql -uroot -p''            #####单引号内直接输入密码可直接登录
[root@localhost home]# mysql -uroot -p              #####根据提示输入密码后登录

登录后可查看所有库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

远程访问需要如下操作:

  1. 关闭防火墙
  2. 授予root用户远程访问权限
#######查看防火墙状态
[root@localhost home]#  service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10050 
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

#######关闭防火墙
[root@localhost home]#  service iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]

#######查看防火墙状态
[root@localhost home]#  service iptables status
iptables:未运行防火墙。
####################查询root用户远程访问权限
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user, host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

####################授予root用户远程访问权限:
mysql> grant all privileges on *.* to root@'%' identified by '5TGB^&8ik,';
Query OK, 0 rows affected, 1 warning (0.00 sec)


####################刷新权限,使设置生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

到这里应该就可以正常使用,记得开通到服务器的3306端口访问权限

参考的文章都是CentOS 7的 ,6的比较少

参考文章1:centos7.2下安装mysql5.7,使用rpm包安装

参考文章2:Linux/Centos7以RPM方式安装mysql-5.7.23

参考文章3:Linux安装mysql(mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar)

参考文章4:centos7下安装mysql5.7(rpm)

参考文章5:   https://www.linuxidc.com/Linux/2018-08/153595.htm

新增如下:

1.设置允许远程登录
Mysql默认不允许远程登录,我们需要设置下,并且防火墙开放3306端口;

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit;

Bye

退出下;

[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[root@localhost ~]# firewall-cmd --reload

success

[root@localhost ~]#

开放3306端口
 

2.修改访问权限

目的:任何主机通过用户root和密码password11连接到mysql服务器

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

3.配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect=‘SET NAMES utf8’

[root@localhost ~]# vi /etc/my.cnf

编辑保存完 重启mysql服务;

查看下编码: mysql> show variables like '%character%';

猜你喜欢

转载自blog.csdn.net/guopengNo1/article/details/89208049
今日推荐