Centos7 安装MySQL8.0

MySQL安装和配置

1. 安装

  1. 检查mysql和mysql-server是否安装

    rpm -qa | grep mysql
    rpm -qa | grep mysql-server
  2. 如果之前安装过进行卸载

    yum -y remove mysql*
  3. 下载安装MySQL的repo源
    https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm

    wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
    rpm -ivh mysql80-community-release-el7-3.noarch.rpm
  4. 安装mysql 服务器(一路yes)

    yum install mysql-community-server
  5. 安装成功后启动服务

    systemctl start mysqld
  6. 查看默认密码

    sudo grep 'temporary password' /var/log/mysqld.log
  7. 查看3306端口是否开放

    netstat –ant
  8. 将mysql添加为自启动服务

    systemctl enable mysqld

2. 配置

  1. 登录MySQL,密码为之前第6步查询出来的

    mysql -u root -pxxx
  2. 修改 root 登录密码 (此时密码要根据密码规则设定)

    alter user 'root'@'localhost' identified by 'xxx';
  3. 默认MySQL只允许localhost 登录,修改允许其他主机连接

    CREATE USER 'root'@'%' IDENTIFIED BY 'password';
    GRANT ALL ON *.* TO 'root'@'%';
    FLUSH PRIVILEGES;
    ## 查看更新后数据
    use mysql;
    select host, user, authentication_string, plugin from user;
  4. 创建其他用户并赋权

    create user ‘用户名’@’访问主机’ identified by ‘密码’;
    grant 权限列表 on 数据库.表 to ‘用户名’@’访问主机’;(修改权限时在后面加with grant option)

附录:

你可能感兴趣的:(mysql)