centos 7.2 配置mysql

1.下载MySQL源

  wget http://dev.MySQL.com/get/mysql57-community-release-el7-7.noarch.rpm
 
2.安装MySQL源
  rpm -ivh mysql57-community-release-el7-7.noarch.rpm
 
3.安装mysql-community-server
  yum install mysql-community-server -y
 
4.重启mysql
  systemctl restart mysqld
  注:自动启动服务用 systemctl enable mysql
 
5.查看临时密码
  grep 'A temporary password' /var/log/mysqld.log
  2015-12-24T08:04:50.296020Z 1 [Note] A temporary password is generated for root@localhost: I(eKs9PyklP_
 
6.用临时密码登录mysql并修改root密码,新增用户,打开远程访问
  >mysql -uroot -p
  Enter password:
  Welcome to the MySQL monitor.  Commands end with ; or g.
  Your MySQL connection id is 15
  Server version: 5.7.10 MySQL Community Server (GPL)
 
  Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
 
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
 
  Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
  mysql> set global validate_password_policy=0;
  mysql> set global validate_password_length=1;
  mysql> alter user 'root'@'localhost' identified by 'root';  // 备注:这里换成自己的密码
  Query OK, 0 rows affected (0.00 sec)
  mysql> flush privileges;
  Query OK, 0 rows affected (0.00 sec)
  mysql> create user hadoop identified by 'root';
  Query OK, 0 rows affected (0.00 sec)
  mysql>grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;   //备注:这里是为了可以远程访问数据库
  Query OK, 0 rows affected, 1 warning (0.00 sec)
 
 附(在应用的时候会遇到的错误信息,及解决办法):
  1.用group by的时候报错,需要改配置文件
    /etc/my.cnf
    在最后加入
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    然后重启mysql
    systemctl restart mysqld
 
  2.导入失败,报错 
  MySQL Got a packet bigger than 'max_allowed_packet' bytes错误
  修改方法
  2.1、修改配置文件
  可以编辑my.cnf来修改(windows下my.ini),在[mysqld]段或者mysql的server配置段进行修改。
  max_allowed_packet = 20M
  如果找不到my.cnf可以通过
  mysql --help | grep my.cnf
  去寻找my.cnf文件。
  linux下该文件在/etc/下。
  2.2、在mysql命令行中修改
  在mysql 命令行中运行
  set global max_allowed_packet = 2*1024*1024*10
  然后退出命令行,重启mysql服务,再进入。
  show VARIABLES like '%max_allowed_packet%';
原文地址:https://www.cnblogs.com/zhgblog/p/7403376.html