准备
1. 首先,查看系统是否已经安装了mysql数据库
rpm -qa | grep mysql
演示如下:
[root@localhost etc]# rpm -qa | grep mysql
mysql-community-libs-8.0.16-2.el7.x86_64
mysql-community-common-8.0.16-2.el7.x86_64
mysql-community-client-8.0.16-2.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-server-8.0.16-2.el7.x86_64
2. 查询到已安装的MySQL库后,执行以下命令依次卸载
yum remove mysql-xxx-xxx
若没有查询后,没有安装Mysql库,可直接跳过此步。
3. 删除mysql的配置文件(MySQL卸载不会自动删除配置文件,需自行清理)
首先使用如下命令查找出所用的配置文件
find / -name mysql
[root@localhost etc]# find / -name mysql
/etc/logrotate.d/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/etc/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/usr/include/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/usr/include/mysql/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
根据需求使用以下命令 依次 对配置文件进行删除
rm -rf /var/lib/mysql
1.使用rpm 命令查找出要删除的mariadb文件,命令如下
rpm -qa | grep mariadb
可能出现结果
mariadb-libs-5.5.56-2.el7.x86_64
删除上面的程序
yum -y remove mariadb-libs.x86_64
安装
mysql 官网地址
wget http://mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server (费时)
配置
1.启动,配置开机启动mysql
systemctl start mysqld.service
systemctl enable mysqld.service
2.修改 my.cnf
vim /etc/my.cnf
在my.cnf文件最后一行加上: skip-grant-tables ,退出
3.重启msyql
systemctl restart mysqld
4.免密登录mysql
mysql -u root -p ,然后直接enter
5.修改密码,设置远程连接
use mysql;
UPDATE USER SET authentication_string='' WHERE USER ='root';
quit 退出mysql
删除刚才在 my.cnf 文件添加的最后一行 vim /etc/my.cnf , skip-grant-tables ,保存退出
重启mysql, systemctl restart mysqld
登录mysql,mysql -u root -p , 直接 enter
修改root 密码, ALTER USER 'root'@'localhost' IDENTIFIED BY ‘Aaa@1234’; (密码由大小写字码符号数字组成)
修改host ,UPDATE USER SET host = '%' WHERE user = 'root';
更改加密方式,ALTER USER 'root'@'%' IDENTIFIED BY 'Aaa@1234' PASSWORD EXPIRE NEVER;
重新设置密码,ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Aaa@1234';
flush privileges;
重启mysql ,systemctl restart mysqld
用mysql 工具连接数据库(问题:查看虚拟机能否ping通主机,防火墙是否关闭)