下载需要安装rpm文件
- 下载地址:https://dev.mysql.com/downloads/mysql/
- 选择需要安装在rpm文件,可选择:Bundle包
- tar需要解压:命令:tar -xvf 包名
执行安装命令
yum -y install mysql-community-common-8.0.20-1.el8.x86_64.rpm
yum -y install mysql-community-libs-8.0.20-1.el8.x86_64.rpm
yum -y install mysql-community-client-8.0.20-1.el8.x86_64.rpm
yum -y install mysql-community-server-8.0.20-1.el8.x86_64.rpm
或者使用
yum -y install mysql-community-{server,client,common,libs}-*
- 执行查看安装是否成功命令
rpm -qa | grep mysql
能看到一下文件
- 查看mysql启动状态
systemctl status mysqld.service
- 启动mysql
systemctl start mysqld.service
- 重启mysql服务
systemctl restart mysqld.service
- 'root'@'localhost创建 一个超级用户帐户。设置超级用户的密码并将其存储在错误日志文件中。要显示它,请使用以下命
sudo grep 'temporary password' /var/log/mysqld.log
- 查看临时密码
cat /var/log/mysqld.log | grep password
- 登录命令
mysql -uroot -p
- 输入临时密码
- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
- 重启mysql服务
- 登录成功后远程是不能访问的需要开启权限
show databases;
use mysql;
- 查询用户
select Host,User from user;
修改root密码
update user set Host='%' where User='root';
- 重启mysql服务
此时外部可以访问了,如果还不能访问检查一下防火墙是否开启,开启则需要将端口号加入
忘记密码处理
- 停止mysql
service mysqld stop
- 修改my.cof文件
vim /etc/my.cnf
添加: skip-grant-tables
- 启动mysql
service mysqld start
- 登陆mysql
mysql -u root
运行语句:use mysql;
注意下面语句localhost和%的区别,下面截图中是%就用%是localhost就用localhost
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ZzS$2020#';
alter user 'root'@'%' IDENTIFIED BY 'ZzS$2020#';
报错:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决方案:flush privileges;
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
就是语句中在问题
- 修改完成后把my.cof中添加skip-grant-tables删除掉
- 重启mysql
service mysqld restart