先查看自己电脑死否安装mysql
查看是否还有mysql软件:
rpm -qa|grep mysql
1 .查看系统中是否以rpm包安装的mysql:
[root@localhost opt]# rpm -qa | grep -i mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686
2.卸载myql
[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686
3.删除分散mysql文件夹
[root@localhost local]# whereis mysql 或者 find / -name mysql
mysql: /usr/lib/mysql /usr/share/mysql
4.清空相关mysql的所有目录以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
rm -rf /usr/my.cnf
安装MySQL
cd /usr/local/src/
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server
启动服务
service mysqld start //启动mysql
service mysqld status //查看mysql启动状态
chkconfig mysqld on //设置mysql开机自启动
查看密码并修改密码-- mysql8.0以后默认安装密码为0
grep 'temporary password' /var/log/mysqld.log
set password=password(“密码”);
这种方式适合8.0以下版本
MySQL8.0版本设置root账号密码
use mysql;
update user set authentication_string = '数据库密码' where user = 'root';