Centos7安装mysql

新地址

https://blog.csdn.net/qq_30758673

下载安装mysql

  • 卸载自带的迷你库

rpm -qa | grep mariadb | xargs rpm -e --nodeps

  • 下载yum镜像下载源

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

  • 安装yum下载源

yum -y install mysql57-community-release-el7-10.noarch.rpm

  • 开始下载

yum -y install mysql-community-server

配置mysql

  1. 启动MySQL服务

systemctl start mysqld.service

  1. 设置mysql自启

systemctl enable mysqld.service

  1. 首次登录mysql
  2. 设置root用户名密码
    • 初始密码在/var/log/mysqld.log

    grep "password" /var/log/mysqld.log

    • 输入初始密码进入数据库

    mysql -uroot -p

    • 设置密码密码安全级别

    SET global validate_password_policy=0;

    • 设置密码长度

    set global validate_password_length=1;

    • 添加root用户

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

    • 设置外部主机访问本地数据库

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

    • 刷新设置 flush privileges;