Centos7离线安装Mysql 5.7.9

1.在Centos 7上先要卸载 mariadb-lib

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


2.到mysql官网下载liunx 64位版本,或者使用liunx指令网络安装 官网下载: http://www.mysql.com/
我这里分享我自己在mysql网站下载的最新版本:链接: http://pan.baidu.com/s/1kVhmHWb 密码: 2ikt
下载后,放置到Centos 服务器的/usr/local/ 文件夹上解压 :

    
    
  1. [root@centos-linux ~]# lsmysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
  2. [root@centos-linux ~]# tar xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar
解压后,出现如下文件:

    
    
  1. mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
  2. mysql-community-devel-5.7.16-1.el7.x86_64.rpm
  3. mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm
  4. mysql-community-libs-5.7.16-1.el7.x86_64.rpm
  5. mysql-community-common-5.7.16-1.el7.x86_64.rpm
  6. mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm
  7. mysql-community-test-5.7.16-1.el7.x86_64.rpm
  8. mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm
  9. mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm
  10. mysql-community-server-5.7.16-1.el7.x86_64.rpm
  11. mysql-community-client-5.7.16-1.el7.x86_64.rpm
  12. mysql-community-embedded-5.7.16-1.el7.x86_64.rpm


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

    
    
  1. [root@centos-linux ~]# rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
  2. [root@centos-linux ~]# rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
  3. [root@centos-linux ~]# rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
  4. [root@centos-linux ~]# rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm


数据库初始化:
在 Liunx 系统中,为了保证数据库目录为与文件的所有者为 mysql 登陆用户,如果你是以 root 身份运行 mysql 服务,需要执行下面的命令初始化
	[root@centos-linux ~]# mysqld --initialize --user=mysql
    
    


如果是以 mysql 身份运行,则可以去掉 --user 选项。
另外 --initialize 选项默认以“安全”模式来初始化,则会为 root 用户生成一个密码并将该密码标记为过期,登陆后你需要设置一个新的密码,而使 用 --initialize-insecure 命令则不使用安全模式,则不会为 root 用户生成一个密码。
这里演示使用的 --initialize 初始化的,会生成一个 root 账户密码,密码在log文件里

    
    
  1. [root@localhost local]# cat /var/log/mysqld.log
  2. 2016-11-18T05:17:06.439015Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use -- explicit_defaults_for_timestamp server option (see documentation for more details).
  3. 2016 -11 -18T05: 17: 06.619744Z 0 [ Warning] InnoDB: New log files created, LSN= 45790
  4. 2016 -11 -18T05: 17: 06.656070Z 0 [ Warning] InnoDB: Creating foreign key constraint system tables.
  5. 2016 -11 -18T05: 17: 06.715702Z 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: 3f94e95c-ad4e -11e6-ac8b -000c29994ce5.
  6. 2016 -11 -18T05: 17: 06.716475Z 0 [ Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
  7. 2016 -11 -18T05: 17: 06.717114Z 1 [Note] A temporary password is generated for root@localhost: <.xOzij-F2vr

红色highlight地方就是root账户下生成的随机密码。

启动mysql服务器:

    
    
  1. [root@centos-linux ~]# systemctl start mysqld
  2. [root@centos-linux ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.13Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ' help;' or '\h' for help. Type '\c' to clear the current input statement.
  3. mysql>

修改 root 密码
该密码被标记为过期了,如果想正常使用还需要修改密码
mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
以前的  password() 函数将会被抛弃,官方建议使用下面的命令来修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ' 460502Kfc';

不过要注意mysql 5.7 设定密码和之前版本密码不能太简单,详情请看这里解释:

设置root外网ip访问,并对其授权:
创建一个普通用户 sa ,密码是 some_pass
CREATE USER 'sa' @ '%' IDENTIFIED BY 'some_pass' ;
给这个用户授予 SELECT,INSERT,UPDATE,DELETE 的远程访问的权限,这个账号一般用于提供给实施的系统访问
GRANT SELECT , INSERT , UPDATE , DELETE ON *.* TO 'sa' @ '%' ;
创建一个管理员用户 admin 账号 ,密码是 some_pass
CREATE USER 'admin' @ '%' IDENTIFIED BY 'some_pass' ;
给这个用户授予所有的远程访问的权限。这个用户主要用于管理整个数据库、备份、还原等操作。
GRANT ALL ON *.* TO 'admin' @ '%' ;
使授权立刻生效
flush privileges ;

启动mysql 服务器指令:
启动 MySQL Server
systemctl start mysqld
查看 MySQL Server 状态
systemctl status mysqld
关闭 MySQL Server
systemctl stop mysqld

防火墙设置:(预防iP可以ping接,但是navicat并不能连接的情况)
远程访问 MySQL, 需开放默认端口号 3306.
方式1:iptables(CentOS 7.x版本之前用法,不推荐)
打开 iptables 的配置文件:
vi /etc/sysconfig/iptables
修改
*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
在里面加入这2行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
改为
*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
如果该 iptables 配置文件 不存在,先执行  yum install iptables-services  安装
执行 iptables 重启生效
service iptables restart
方式2:firewall-cmd(推荐)
执行
firewall-cmd --permanent --zone=public --add-port=3306/tcpfirewall-cmd --permanent --zone=public --add-port=3306/udp
这样就开放了相应的端口。
执行
firewall-cmd --reload
使最新的防火墙设置规则生效。

还有其他设置与补充可以查阅这篇文章: http://www.centoscn.com/mysql/2016/0315/6844.html






猜你喜欢

转载自blog.csdn.net/xiaozhaoshigedasb/article/details/88639127