是用xshell6远程控制服务器安装mysql
可以从官网上下载http://dev.mysql.com/downloads/repo/yum/
也可以shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
可以用linux指令查看是否下载成功 ls -l
3.安装mysql源 shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
下载和安装过程中会提示是否继续,输入y Enter继续。
4.检查mysql源是否安装成功 shell> yum repolist enabled | grep "mysql.*-community.*"
shell> yum install mysql-community-server
安装mysql服务完成之后启动mysql服务
shell> systemctl start mysqld
然后就可以查看MySQL的启动状态了。shell > systemctl status mysqld
Active:active(running)表示MySQL服务已经启动
设置开机启动
shell > systemctl enable mysqld
shell > systemctl daemon-reload
如果在启动mysql服务的时候出现
Failed to issue method call: Unit mysql.service failed to load: No such file or directory. See system logs and 'systemctl status mysql.service' for details.
的报错信息,则可能是系统权限的问题,shell > chown -r mysql:mysql /var/lib/mysql/ 进行授权
shell > rpm -qa | grep -i mysql 可以查看已安装了的mysql组件
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
shell > grep 'temporary password' /var/log/mysqld.log
mysql > alter user 'root'@'localhost' identified by 'mysqlpassword'; 或 set password for 'root'@'localhost'=password('mysqlpassword');
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
如果想修改简单易记些的MySQL密码,可以在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略,或直接禁用密码策略,添加 validate_password = off
重新启动(mysql > systemctl restart mysql) mysql服务使配置生效。
重置密码
ALTER USER USER() IDENTIFIED BY 'Xiaoming250';