阿里云配置MySQL

安装MySQL

先查看是否已经安装rpm -qa|grep -i mysql

  1. mysql的repo源
    # wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
    # rpm -ivh mysql57-community-release-el7-7.noarch.rpm
    安装之后会获得/etc/yum.repos.d/mysql-community.repo和/etc/yum.repos.d/mysql-community-source.repo两个repo源
  2. yum安装
    # yum install mysql-server
    # yum install mysql-devel
  3. 启动MySQL
    # service mysqld start启动mysql
    # service mysqld status查看mysql当前的状态
    # service mysqld stop停止mysql
    # service mysqld restart重启mysql

    连接MySQL

  4. 首次登陆需要先查看默认密码 # cat /var/log/mysqld.log | grep password
  5. 登录MySQLmysql -u root -h localhost -p 输入密码
  6. 首次操作要先修改密码,但默认安全级别为最高,需手动调低,不然设置密码会很容易提示太简单而修改失败
    set global validate_password_policy=0;
  7. 修改密码 set PASSWORD = PASSWORD('123456');

配置远程连接MySQL

  1. 首先配置阿里云安全组规则,允许开放3306接口
  2. 登录MySQL
    可以设置对所有IP开放update user set host='%' where user='root' and host='localhost';
    也可以将host指定为某个ipupdate user set host='106.39.178.131' where user='root' and host='localhost';
  3. 刷新权限表,使配置生效 flush privileges;

至此即可远程连接MYSQL

参考链接:
阿里云下配置MySQL远程连接