本文主要是介绍Centos7yum安装mysql5.7,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、配置YUM源
在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ ,
这里我是提前把自己阿里云yum换成了163yum
下载mysql源安装包
none>wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
none>yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
shell>yum repolist enabled | grep "mysql.*-community.*"
[root@lry home]# yum repolist enabled | grep “mysql.-community.”
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration看到上图所示表示安装成功。
可以修改vim/etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。改完之后的效果如下所示:# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
2、安装MySQL
none>yum install mysql-community-server
3、启动MySQL服务
none>systemctl start mysqld
查看MySQL的启动状态
none>systemctl status mysqld
[root@lry home]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since Tue 2018-01-16 15:16:47 CST; 8h agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 17353 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)Process: 17335 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 17357 (mysqld)CGroup: /system.slice/mysqld.service└─17357 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pidJan 16 15:16:47 lry systemd[1]: Starting MySQL Server...
Jan 16 15:16:47 lry systemd[1]: Started MySQL Server.
4、开机启动
none>systemctl enable mysqld
none>systemctl daemon-reload
5、修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
none>sudo grep 'temporary password' /var/log/mysqld.log
none>mysql -uroot -p
mysql>alter user ‘root’@’localhost’IDENTIFIED BY ‘新密码’;
或者
mysql>set password for ‘root’@’localhost’=password(‘新密码’);
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy thecurrent policy requirements错误,
通过msyql环境变量可以查看密码策略的相关信息:mysql
validate_password_policy:密码策略,默认为MEDIUM策略 validate_password_dictionary_file:密码策略文件,策略为STRONG才需要 validate_password_length:密码最少长度 validate_password_mixed_case_count:大小写字符长度,至少1个 validate_password_number_count :数字至少1个 validate_password_special_char_count:特殊字符至少1个 上述参数是默认策略MEDIUM的密码检查规则。
共有以下几种密码策略:
0 or LOW
Length
1 or MEDIUM
Length; numeric, lowercase/uppercase, and special characters
2 or STRONG
Length; numeric, lowercase/uppercase, and special characters; dictionary file
MySQL官网密码策略详细说明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
修改密码策略
在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略
选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
validate_password_policy=0
如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
validate_password= off
重新启动mysql服务使配置生效:
systemctlrestart mysqld
6、添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
grant all privileges on *.* to 'root'@'%'(客户端ip) identified by '用户的密码'(这里指root登陆mysql的密码) with grant option;
mysql>flush privileges;
7、配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
symbolic-links=0log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password_policy=0
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务,查看数据库默认编码如下所示:
默认配置文件路径: 配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid
这篇关于Centos7yum安装mysql5.7的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!