centos安装Mysql

Centos7.6 安装Mysql8

更换yum源地址(阿里云不需要更换源)

  • 备份

    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    
  • 更换源

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    
  • 生成缓存

    yum makecache
    

安装Mysql8

  • 在centos启用Mysql yum存储库

    rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
    
  • 安装mysql8社区服务器(由于mysql yum存储库具有用于多个版本的mysql存储库配置,因此需要禁用mysql repo文件中的所有存储库)

    sed -i ‘s/enabled=1/enabled=0/‘ /etc/yum.repos.d/mysql-community.repo
    
  • 安装mysql80

    yum --enablerepo=mysql80-community install mysql-community-server
    
  • 查看mysql的状态

    service mysqld status
    
  • 启动mysql服务

    service mysqld start
    
  • 查询mysql的默认密码(安装的过程中,会给root账号授予一个临时密码,该密码用于修改真实的密码)

    grep "A temporary password" /var/log/mysqld.log
    
  • mysql安全安装

    mysql_secure_installation
    

    提示输入当前的密码

    Enter password for user root:
    

    在上方输入临时密码,安装Enter。将提示一下信息

    The existing password for the user account root has expired. Please set a new password.
    
    New password:
    Re-enter new password:
    

    需要为root账户输入两次新的密码。默认输入yes(y)

    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
    
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
    
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    
  • 重启mysql服务

    service mysqld restart
    
  • 设置开机自启动

    chkconfig mysqld on
    
  • 设置远程访问

    mysql> use mysql;
    

    查看user用户

    mysql> select user,host from user;
    +------------------+-----------+
    | user             | host      |
    +------------------+-----------+
    | mysql.infoschema | localhost |
    | mysql.session    | localhost |
    | mysql.sys        | localhost |
    | root             | localhost |
    +------------------+-----------+
    

    创建root远程用户(输入你的password)

    mysql> create user ‘root‘@‘%‘ identified by ‘yourpassword‘;
    

    授权用户可以远程登陆

    mysql> grant all on *.* to ‘root‘@‘%‘;
    

    修改加密方式(输入你的password)

    mysql> alter user ‘root‘@‘%‘ identified with mysql_native_password by ‘yourpassword‘;
    

    刷新权限

    mysql> flush privileges;
    

    查看防火墙状态

    systemctl status firewalld
    

    开启防火墙

    systemctl start firewalld
    

    添加端口号

    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    

    刷新重置

    firewall-cmd --reload
    

阿里云服务器需要进入到网页系统中,开启安全组中的端口3306

centos安装Mysql

上一篇:MySQL基础--函数


下一篇:查询 数据库 中 表列 主外键关联