• redhat上安装MySQL5.7.12


    0.下载mysql

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

    1.查找是否安装
    [root@mysql opt]# rpm -qa|grep mysql
    查找是否安装mysql,结果如下
    mysql-libs-5.1.73-3.el6_5.x86_64
    [root@mysql opt]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64
    卸载mysql
    [root@cmos1 mysql]# rpm -qa | grep mysql
    mysql-libs-5.1.73-3.el6_5.x86_64
    [root@cmos1 mysql]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64
    [root@cmos1 mysql]# rpm -qa | grep mysql
    [root@cmos1 mysql]#

    2. 解压

    tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar

    解压完成后由这么几个文件:

    mysql-community-client-5.7.12-1.el6.x86_64.rpm
    mysql-community-common-5.7.12-1.el6.x86_64.rpm
    mysql-community-devel-5.7.12-1.el6.x86_64.rpm
    mysql-community-embedded-5.7.12-1.el6.x86_64.rpm
    mysql-community-embedded-devel-5.7.12-1.el6.x86_64.rpm
    mysql-community-libs-5.7.12-1.el6.x86_64.rpm
    mysql-community-libs-compat-5.7.12-1.el6.x86_64.rpm
    mysql-community-server-5.7.12-1.el6.x86_64.rpm
    mysql-community-test-5.7.12-1.el6.x86_64.rpm

    3.开始安装
    根据需要安装:
    mysql-community-client-5.7.12-1.el6.x86_64.rpm
    mysql-community-common-5.7.12-1.el6.x86_64.rpm
    mysql-community-libs-5.7.12-1.el6.x86_64.rpm
    mysql-community-server-5.7.12-1.el6.x86_64.rpm
    mysql-community-devel-5.7.12-1.el6.x86_64.rpm
    执行安装的示例:
    rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
    rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
    rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
    rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
    rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
    过程如下:
    [root@cmos1 mysql]# rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
    warning: mysql-community-common-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ########################################### [100%]
    1:mysql-community-common ########################################### [100%]
    [root@cmos1 mysql]# rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
    warning: mysql-community-libs-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ########################################### [100%]
    1:mysql-community-libs ########################################### [100%]
    [root@cmos1 mysql]# rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
    warning: mysql-community-devel-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ########################################### [100%]
    1:mysql-community-devel ########################################### [100%]
    [root@cmos1 mysql]# rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
    warning: mysql-community-client-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ########################################### [100%]
    1:mysql-community-client ########################################### [100%]
    [root@cmos1 mysql]# rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
    warning: mysql-community-server-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing... ########################################### [100%]
    1:mysql-community-server ########################################### [100%]
    [root@cmos1 mysql]#

    ===================================================
    不要
    4.启动mysql
    service mysql start
    或者使用如下命令:
    /etc/init.d/mysql start
    5. 此处没有设置密码,会报错
    #1045 - Access denied for user 'root'@'localhost' (using password: NO)
    解决方法是用安全方式登录,修改密码即可。


    4.mysql安全方式启动:
    mysqld_safe --user=mysql --skip-grant-tabes --skip-networking &


    由于mysql5.7 中mysql.user 表中没有Password字段,用authentication_string 代替即可。

    6. 至此mysql安装完成,可用客户端工具连接使用了.

    ===================================================

    4.修改配置,跳过密码检测
    [root@mysql MySQL]#vi /etc/my.cnf
    修改配置文件
    加入 skip-grant-tables
    跳过密码检测

    5.启动mysql
    [root@mysql MySQL]#service mysqld start
    启动mysql,过程如下:
    [root@cmos1 mysql]# service mysqld start
    Initializing MySQL database: [ OK ]
    Installing validate password plugin: [ OK ]
    Starting mysqld: [ OK ]
    [root@cmos1 mysql]#
    [root@mysql MySQL]#mysql –u root –p
    登录,无需密码直接回车
    过程如下:
    [root@cmos1 mysql]# 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.12 MySQL Community Server (GPL)

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

    7.设置密码
    mysql>use mysql;
    选择数据库
    mysql>update user set password_expired="N" where user="root";
    设置密码失效为”N”
    mysql>update user set authentication_string=password("123456") where user="root";
    设置密码为”123456”
    mysql>flush privileges;
    刷新生效
    mysql>quit;
    退出

    8.修改配置,恢复密码检测
    [root@mysql MySQL]#vi /etc/my.cnf
    修改配置
    注释或删除 #skip-grant-tables

    9.用密码登录
    [root@mysql MySQL]#mysql –u root –p
    用新密码登陆

    10.修改密码
    [root@mysql MySQL]#mysqladmin -u用户名 -p旧密码 password 新密码
    [root@mysql MySQL]#mysqladmin -uroot –p123456 password “123-abcABC“
    mysql>set password=password("123456");

    11.查看现有的密码策略
    mysql>show variables like 'val%';

    validate_password_dictionary_file参数是指定密码验证的字典文件路径。
    validate_password_length参数是密码的长度,这个参数由下面的公式生成
    validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)
    validate_password_mixed_case_count参数是密码中英文字符大小写的个数,当密码策略是MEDIUM或以上时生效。
    validate_password_number_count参数是密码中至少含有的数字个数,当密码策略是MEDIUM或以上时生效。
    validate_password_policy这个参数可以设为0、1、2,分别代表从低到高的密码强度,此参数的默认值为1,如果想将密码强度改若,则更改此参数为0。
    validate_password_special_char_count参数是密码中非英文数字等特殊字符的个数,当密码策略是MEDIUM或以上时生效。

    12.更改密码策略
    mysql> set global validate_password_length=0; --更改密码长度
    mysql> set global validate_password_policy=0; --更改密码策略为LOW

    13.允许mysql远程访问
    赋予任何主机访问数据的权限
    mysql>grant all privileges on *.* to 'root'@'%'with grant option;
    会报错:ERROR 1133 (42000): Can't find any matching row in the user table
    其实如果事先在mysql.user表中存在root用户就正常了,或,将这句末尾加上identified by '密码' 也就正常了。如下面的命令行
    mysql>grant all privileges on *.* to 'root'@'%'identified by '123456' with grant option;

    14.设置编码,解决乱码问题
    default-character-set=utf-8
    通过在/etc/my.cnf中增加参数default-character-set=utf-8解决乱码问题
    15.查看防火墙状态
    systemctl status firewalld
    临时关闭防火墙命令。重启电脑后,防火墙自动起来
    systemctl stop firewalld
    永久关闭防火墙命令。重启后,防火墙不会自动启动
    systemctl disable firewalld
    打开防火墙命令systemctl enable firewalld
    16.mysql默认已是开机自启动

  • 相关阅读:
    对于未来的搜索引擎的思考!
    [转]《C陷阱与缺陷》读书笔记——前车之覆,后车之鉴
    C语言深度解剖笔记
    感觉压力挺大的!!
    发现中国的代理服务器很少
    我的博客搬家了
    [转]22+1条经典的编程引言
    [转]想象五年之后的你
    什么叫做卷积
    《30天自制操作系统》读书笔记(1)读前感
  • 原文地址:https://www.cnblogs.com/duanxz/p/2810860.html
Copyright © 2020-2023  润新知