1、查看mysql安装了哪些东西:rpm -qa | grep -i mysql
mysql57-community-release-el7-11.noarch
mysql-community-libs-5.7.28-1.el7.x86_64
mysql-community-server-5.7.28-1.el7.x86_64
mysql-community-common-5.7.28-1.el7.x86_64
mysql-community-client-5.7.28-1.el7.x86_64
2、yum 卸载、删除mysql
yum remove mysql57-community-release-el7-11.noarch
.....
yum remove mysql-community-client-5.7.28-1.el7.x86_64
3、查找mysql相关目录:find / -name mysql
,删除相关目录:rm -rf /var/lib/mysql ...
4、删除mysql 配置文件:rm –rf /usr/my.cnf
,rm -rf /root/.mysql_sercret
至此卸载干净。
1、创建一个目录:mkdir /use/local/mysql
,进入目录:cd /use/local/mysql
2、yum源安装
-- 下载mysql yum源
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
-- 安装yum源
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
3、安装mysql
yum install mysql-community-server
4、成功安装之后重启mysql服务:
/bin/systemctl restart mysqld.service
5、此时登陆:mysql -uroot -p
报错
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
6、查看默认密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。
-- 使用此命令快捷查看
grep "password" /var/log/mysqld.log
7、设置密码校验
设置密码报错如下,原因是你设置的密码不符合密码校验,此时需要修改校验。
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>set global validate_password_policy=LOW;
mysql>set global validate_password_length=4;
密码验证设置结束,在试试修改密码。
8、修改默认密码
mysql进行修改:
-- 设置密码
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
-- 刷新
mysql>FLUSH PRIVILEGES;
连接时报错
1130-host'111. 201.124. is not allowed to connect to this MYSQL server
原因是数据库需要设置允许远程登陆
,默认是"localhost" ,需要修改为"%"
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>flush privileges;
mysql>exit;