1首先第一步,你要在虚拟机中有一个CentOs的环境

2:安装Mysql

(1):下载mysql源安装包

shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

(2):安装mysql源

shell> yum localinstall mysql57-community-release-el7-10.noarch.rpm

(3):安装MySql

  shell> yum install mysql-community-server
(4):启动mysql

systemctl start mysqld

(5)开机启动
  shell> systemctl enable mysqld
  shell> systemctl daemon-reload

(6)初始化密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
  shell> grep 'temporary password' /var/log/mysqld.log
  用VI 查看mysqld.log这个文件,找到 temporary password 后面跟着的密码,然后用这个密码登陆系统
  shell> mysql -uroot -p
 

 修改:密码最小长度策略

mysql> set global validate_password_length=0;

 

  修改:密码强度检查等级策略,0/LOW、1/MEDIUM、2/STRONG

mysql> set global validate_password_policy=0;

 

  修改密码

mysql> set password for 'root'@'localhost' = password('root123');

 

(7):开启外部访问

开启mysql的root用户远程连接服务(%号即远程连接,IDENTIFIED BY后面跟的密码)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root123' WITH GRANT OPTION;

 

  刷新

mysql> flush privileges;

  开启mysql端口服务

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
service network restart