1、下载MySQL repo配置文件
centos7默认yum源中没有mysql,需要到mysql官网下载mysql repo配置文件
[root@docker01 ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm [root@docker01 ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
2、yum 安装mysql-community-server
[root@docker01 ~]# yum -y install mysql-community-server //在线安装mysql
补充:如遇服务器无法连接外网情况(如非离线安装mysql请忽略)
1、在能联外网的centos7服务器上down下mysql安装包及其依赖,执行 # yum -y install mysql-community-server --downloadonly --downloaddir=/opt/mysql 2、将/opt/mysql上传至离线服务器上,执行 # rpm -ivh *.rpm --nodeps --force
3、启动mysql并加入开机自启
[root@docker01 ~]# systemctl start mysqld && systemctl enable mysqld
4、修改my.cnf配置文件
如下配置只是测试环境配置,如生产环境根据实际情况配置
[root@mysql1 mysql]#vi /etc/my.cnf 最下面添加: validate_password_policy=0 //表示将密码安全等级设置为low validate_password = off //关闭密码强度校验 lower_case_table_names=1 //不区分大小写 character-set-server=utf8 //设置字符集 max_connections = 1000 //设置数据库的最大连接数 log_bin_trust_function_creators=1 //二进制日志开关 重启mysql服务 [root@docker01 ~]# systemctl restart mysqld
5、获取mysql的临时密码
[root@docker01 ~]# grep ‘temporary password‘ /var/log/mysqld.log
2021-08-27T07:10:56.227499Z 1 [Note] A temporary password is generated for root@localhost: /,yr=yl2=kpI //为初始密码
6、登录mysql,密码权限修改
[root@docker01 ~]# mysql -uroot -p Enter password: //初始密码为上一步骤获取的临时密码 mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘; //修改root密码 Query OK, 0 rows affected (0.00 sec) mysql> grant all on *.* to ‘root‘@‘%‘ identified by ‘123456‘; //让任意主机都可以root用户远程连接数据库 Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
7、Navicat工具远程连接数据库