MySQL安装及配置

本人是在centos7上使用yum安装,因为使用了国内的yum镜像,使用 yum list | grep 查看到的版本非常低。因此先添加mysql官方repo,这里使用的是centos7的,更多版本可以在http://dev.mysql.com/downloads/repo/yum/查看下载。

  1. 下载repo安装包: wget http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
  2. 安装repo包: yum -y localinstall mysql57-community-release-el7-8.noarch.rpm
  3. 安装mysql: yum -y install mysql-community-server
  4. 启动mysql: systemctl start mysqld.service
  5. 设置开机自启动: systemctl enable mysqld.service
  6. 初次启动时,mysql会自动创建密码,查看默认密码: grep 'temporary password' /var/log/mysqld.log
  7. 修改mysql默认密码:

    1
    2
    shell> mysql -u root -p
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
  8. 修改远程连接权限,此时从远程机器上连接将会提示ERROR 1130 – Host ‘localhost’ is not allowed to connect to this MySQL server,需要使用如下方法修改权限,该方法设置允许任何远程ip通过密码连接该数据库:

    1
    2
    3
    4
    5
    shell> mysql -u root -p
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
    mysql> FLUSH PRIVILEGES;
    mysql> quit;
    shell> systemctl restart mysqld.service

至此,安装及配置完毕。

0%