1.配置YUM源
下载mysql源安装包:
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch
安装mysql源,安装过程中遇到Is this ok [y/d/N]的直接输入y即可:
yum localinstall mysql57-community-release-el7-11.noarch.rpm
检查mysql源是否安装成功:
yum repolist enabled | grep "mysql.*-community.*"
2.安装MySQL,安装过程中遇到Is this ok [y/d/N]的直接输入y即可
yum install mysql-community-server
Note:可通过修改/etc/yum.repos.d/mysql-community.repo源中的enabled【1表示选择】的值来选择安装的MySQL版本
3.启动MySQL服务
systemctl start mysqld
查看MySQL的启动状态
systemctl status mysqld
4.开机启动
systemctl enable mysqld
systemctl daemon-reload
5.修改root本地登录密码
获取MySQL默认密码:
grep 'temporary password' /var/log/mysqld.log
登陆MySQL:
mysql -uroot -p
修改默认密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password';
或者
set password for 'root'@'localhost'=password('Password');
Note:MySQL5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。?
6.添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户:
GRANT ALL PRIVILEGES ON *.* TO 'account'@'%' IDENTIFIED BY 'pwd' WITH GRANT OPTION;
7.配置默认编码为utf8
show variables like '%character%';
修改/etc/my.cnf配置文件:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务即可完成修改
8.默认配置文件路径
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid