• centos7安装mysql


    1、先检测系统是否自带原有版本mysql安装包,如果有要先卸载删除,不然不能成功安装和启动;

    rpm -qa|grep mysql  
    yum remove mysql mysql-server mysql-libs compat-mysql51    注意这个代码,卸载不干净
    rm -rf /etc/my.cnf

    a)删除分散mysql文件夹

    whereis mysql 

    /usr/lib/mysql /var/lib64/mysql

    清空相关mysql的所有目录以及文件
    rm -rf /usr/lib/mysql
    rm -rf /usr/share/mysql

    rm -rf /usr/my.cnf

    2、安装MySQL

    wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

     
    rpm -ivh mysql57-community-release-el7-9.noarch.rpm
     
    yum install mysql-community-server

    3、MySQL的启动配置

    4. 防火墙设置

    centos7 防火墙设置

    第一种 firewall
    永久的开放、关闭、查看端口
    sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent
    sudo firewall-cmd --zone=public --remove-port=3000/tcp --permanent
    sudo firewall-cmd --zone=public --query-port=3306/tcp
    sudo firewall-cmd --reload

    之后检查新的防火墙规则
    firewall-cmd --list-all


    //检查防火墙状态
    firewall-cmd --state

    systemctl enable firewalld
    systemctl disable firewalld
    systemctl start firewalld
    systemctl stop firewalld
    systemctl restart firewalld
    systemctl status firewalld


    第二种 iptables
    CentOS7默认的防火墙不是iptables,而是firewalld
    关闭firewall:
    systemctl stop firewalld
    systemctl disable firewalld #禁止firewall开机启动

    #安装iptables-services
    yum install iptables-services

    vim /etc/sysconfig/iptables

    service iptables restart
    service iptables save

    5. 数据库初始化

    mysql5.7.6以后的版本在启动数据库的时候,会生成密码放到日志文件里,可从从日志获取:

    [root@localhost local]# cat /var/log/mysqld.log | grep 'password'
    2017-02-08T10:48:53.368640Z 1 [Note] A temporary password is generated for root@localhost: lRym!ofXx6/r
    日志的第一条最后那串字符就是初始密码,这里是 lRym!ofXx6/r
    使用该密码登录即可

    [root@localhost local]# mysql -uroot -p
    Enter password:
    登录后输入sql语句发现

    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    意思是要修改初始密码,修改方法如下(这里密码是Xm123456@):

    mysql> set password='Xm123456@';
    Query OK, 0 rows affected (0.00 sec)
    mysql> quit
    Bye
    用新密码重新登录即可,测试可以执行sql语句了,到此修改初始root密码完成。


    --设置外面客户端可登陆
    show databases;
    use mysql
    select host,user from user;
    update user set host='%' where user='root' and host='localhost';
    flush privileges;
    好了


    --设置简单密码
    set global validate_password_policy=0;
    set global validate_password_length=4;


    --权限设置
    grant all privileges on *.* TO 'root'@'%' identified by 'root' with grant option;
    flush privileges;

    --创建用户
    create user 'risk'@'%' identified by 'risk';
    grant all privileges on *.* to 'risk'@'%' identified by 'risk';
    flush privileges;

  • 相关阅读:
    Elasticsearch Mantanence Lessons Learned Today
    RabbitMQ Exchange & Queue Design Trade-off
    Understanding RabbitMQ Exchange & Queue
    Behind RabbitMQ Exchange Types
    七步,搭建基于Windows平台完美Jekyll博客环境
    How to Change RabbitMQ Queue Parameters in Production?
    Android Weekly Notes Issue #237
    Android Weekly Notes Issue #236
    Android Weekly Notes Issue #235
    Android Weekly Notes Issue #234
  • 原文地址:https://www.cnblogs.com/kaishan1990/p/6693034.html
Copyright © 2020-2023  润新知