mysql5.7安装

  1. 下载MySQL 5.7.22,并放到/usr/local目录下

  2. 登录安装机器,顺序执行如下命令

  yum install -y libaio
  groupadd mysql
  useradd -r -g mysql -s /bin/false mysql
  cd /usr/local
  tar -xvf mysql-5.7.22-el7-x86_64.tar.gz
  ln -s mysql-5.7.22-el7-x86_64 mysql
  cd mysql
  mkdir mysql-files
  chown mysql:mysql mysql-files
  chmod 750 mysql-files
  bin/mysqld --initialize --user=mysql
  bin/mysql_ssl_rsa_setup
  bin/mysqld_safe --user=mysql &
  cp support-files/mysql.server /etc/init.d/mysqld
  1. 至此, mysql启动成功.可运行如下命令,加入系统service
  service mysqld status
  service mysqld start|stop
  
  chkconfig --add /etc/init.d/mysqld
  chkconfig mysqld on
  chkconfig --list
  1. /etc/profile添加mysql环境变量
  export MYSQL_HOME=/usr/local/mysql
  export PATH=$PATH:${MYSQL_HOME}/bin:
  1. 修改root初始密码
    • 在执行上述bin/mysqld --initialize --user=mysql命令时会得到一个root随机初始密码
    • 执行bin/mysql -uroot -pxxx登录
    • 执行set password=password('ins1234');修改root初始密码为ins1234
  2. 拷贝my.cnf/etc目录下作为mysql默认配置

  3. 允许root远程登录
  use mysql;
  grant all privileges  on *.* to root@'%' identified by "ins1234";
  flush privileges;
  select host,user from user; #可以看到roothost变更为%