1、下载安装指令
- -P指定路径
- -i从指定文件获取要下载的URL地址;
- -c继续执行上次终端的任务;断点续传
wget -P /opt/mysql -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
1.2.安装rpm
- -y 自动选择 y
- install 全部安装
yum -y install mysql57-community-release-el7-10.noarch.rpm
1.3.安装mysql服务
yum -y install mysql-community-server
如出错:Error: Unable to find a match: mysql-community-server
禁用本地mysql模块在执行
yum module disable mysql
报错:GPG check FAILED
加上–nogpgcheck在执行
yum install mysql-community-server --nogpgcheck
1.4.启动服务
systemctl start mysqld.service
1.5.查看状态
systemctl status mysqld.service
1.6.获取临时密码
grep "password" /var/log/mysqld.log
A temporary password is generated for root@localhost:这里是密码
2.登录使用MySQL
2.1控制台登录
输入临时密码登录
mysql -u root -p
2.2修改密码
set password for 'root'@'localhost'=password('xxxxxx');
上面指令的root是用户名称,xxxxxx是密码,写一个自己记得住的。密码必须要包含大小写字符和数字,特殊字符也可以用,太简单会提示错误:Your password does not satisfy the current policy
2.3查询数据库访问权限
默认MySQL远程的数据库是仅能localhost
访问,使用navicat等工具连接就会提示1130 - Host 'xxx.xxx.xx.xxx' is not allow to connect to this MySQL server
,如果需要远程访问,需要修改权限
use mysql;
select * from user;
2.4查询数据库访问权限
更新User 表 Host 字段为 ‘%’,代表所有远程主机。
update user set Host='%' where User='root';
刷新权限
flush privileges;
3.重置密码
登录报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
3.1、跳过MySQL的密码认证
vim /etc/my.cnf
在[mysqld]后面任意一行添加
skip-grant-tables
保存后重启
systemctl restatus mysqld.service
3.2登录mysql修改
mysql -u root
mysql> update mysql.user set Password=password('新密码') where User='root';
mysql> flush privileges;
mysql> quit
如出现:ERROR 1054 (42S22): Unknown column 'password' in 'field list'
Password字段不存在修改为authentication_string