1. 下载mysql源安装包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

  1. 安装mysql源  yum localinstall mysql57-community-release-el7-8.noarch.rpm

  2. 检查mysql源是否安装成功  yum repolist enabled | grep "mysql.*-community.*"

  3. 安装MySQL  yum install mysql-community-server

  4. 启动MySQL服务  systemctl start mysqld

  5. 查看MySQL的启动状态  systemctl status mysqld

  6. 查看root用户的密码,(冒号后面得就是密码)  grep 'temporary password' /var/log/mysqld.log

  7. 登录root  mysql -uroot -p

  8. 修改密码  ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPassword';

  9. 添加远程用户  GRANT ALL PRIVILEGES ON *.* TO 'xkj'@'%' IDENTIFIED BY 'a' WITH GRANT OPTION;

  10. 修改编码集 

vim /etc/my.cnf 
(在 [mysqld] 下加) 
character_set_server=utf8 
init_connect='SET NAMES utf8'
  1. 查看编码集  show variables like '%character%'
  2. 给用户添加某个database权限  grant all on dbName.* to 'xkj'@'localhost';
  3. 查看所有用户及权限  SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
  4. 修改字段类型:  alter table address modify column city varchar(50)
  5. 修改表编码集:  ALTER TABLE tableName DEFAULT CHARACTER SET utf8;
  6. 设置编码集:  set character_set_database=utf8;
  7. 查看表的编码集:  show create table tableName