一.安装mysql
1.检查和卸载
# mysqlyum list installed mysql*
# rpm -qa|grep -i mysql
1.1安装过并且需要卸载
# service mysql stop
# rpm -ev MySQL-client-5.5.25a-1.rhel5
# rpm -ev MySQL-server-5.5.25a-1.rhel5
1.1.1删除原来的mysql目录
# find / -name mysql
# whereis mysql
# /var/lib/mysql
# /var/lib/mysql/mysql
# /usr/lib64/mysql
# rm -rf /var/lib/mysql
# rm -rf /var/lib/mysql
# rm -rf /usr/lib64/mysql
1.1.2手动删除my.cnf文件
# rm -rf /etc/my.cnf
1.1.3检查是否删除干净
# rpm -qa|grep -i mysql
卸载依赖
# yum remove mysql-libs
# yum remove mysql-server
# yum remove perl-DBD-MySQL
# yum remove mysql
或者
# yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release
1.2 安装
1.2.1下载
# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
1.2.2安装
# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
1.2.3安装成功后,会在/etc/yum.repos.d/目录下增加了以下两个文件
mysql-community-source.repo 和 mysql-community.repo
1.2.4安装mysql源,下载mysql5.7 rpm源,安装下载好的rpm包
,安装mysql,发现提示,一y到底
# yum install mysql-server
1.2.5 出现 Complete! 代表成功
1.2.6 查看mysql版本号
# mysql -V
二. 启动mysql并修改密码
2.1启动/ 重启
# service mysqld start
# systemctl restart mysqld
2.2 得到初始密码(有坑5.6和5.7的mysql不同,见下文)
# grep "password" /var/log/mysqld.log
# root@localhost: l>KbWhk6K&+Y
2.3 登陆mysql
# mysql -uroot -p'l>KbWhk6K&+Y'
2.4 修改密码SET PASSWORD = PASSWORD(‘你的新密码’); (“需要带数字,大写字母,小写字母,特殊符号”)如我设置密码为 Gxf123456
mysql> SET PASSWORD = PASSWORD('Gxf123456');
2.5 设置密码永不过期并刷新
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
2.6 根据个人需求,设置数据库用户在所有ip下以及在本地可访问,以下用root用户做演示
mysql> grant all privileges on *.* to root@"%" identified by "Gxf123456";
mysql> grant all privileges on *.* to root@"localhost" identified by "Gxf123456";
mysql> flush privileges;
2.7 用 Navicat 连接看是否成功
2.8 退出mysql
mysql> exit
三 遇到的问题
3.1密码不能修改的解决办法5.6和5.7 有区别
SET PASSWORD = PASSWORD('你的新密码'); (5.6)
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密码'); (5.7)
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
3.2密码不符合策略
Your password does not satisfy the current policy requirements
3.2.1 查看策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
3.2.2 首先需要设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW 即可
mysql> set global validate_password_policy=LOW;
3.2.3 当前密码长度为 8 ,如果不介意的话就不用修改了,按照通用的来讲,设置为 6 位的密码,设置 validate_password_length 的全局参数为 6 即可
mysql> set global validate_password_length=6;
3.2.4现在可以为 mysql 设置简单密码了,只要满足六位的长度即可
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
3.3下载途中断网了 再次启动需要强制关掉原yum进程:
# rm -f /var/run/yum.pid
然后就可以使用yum了。如果不行可以重启yum
/sbin/service yum-updatesd restart
3.4 /var/log/mysqld.log 中找不到临时密码
# grep ‘temporary password’ /var/log/mysqld.log
但是,如果以前安装过mysql,这时的mysqld.log中就不会有temporary password
这时就需要删除mysql残留的数据
# rm -rf /var/lib/mysql
执行完毕后需要重新启动MySQL服务
# systemctl restart mysqld
# service mysql restart (5.5.7版本命令)
这时就可以通过上面的命令去查找数据库生成的临时密码了
四 参考链接
https://cloud.tencent.com/developer/article/1496725
https://blog.youkuaiyun.com/lishoubin_198308/article/details/82011783
https://www.cnblogs.com/Lam7/p/6090975.html
https://www.jb51.net/LINUXjishu/499208.html
https://segmentfault.com/q/1010000004196779?_ea=526790
https://blog.youkuaiyun.com/weixin_41679595/article/details/87026158
Ignoring query to other database 解决办法
Your password does not satisfy the current policy requirements 报错处理
You must reset your password using ALTER USER statement before executing this statement 报错处理