[root@iZ8vb8avlmvb451wmm14rqZ ~]# systemctl stop mysqld
检测是否停用 ps -ef|grep mysql
[root@iZ8vb8avlmvb451wmm14rqZ ~]# rpm -qa |grep -i mysql
mysql-common-8.0.26-1.1.al8.x86_64
mysql-server-8.0.26-1.1.al8.x86_64
mysql-8.0.26-1.1.al8.x86_64
mysql-community-release-el7-5.noarch
mysql-errmsg-8.0.26-1.1.al8.x86_64
这种方法可以一下卸载所有mysql8,输入mysql后按tab键补齐然后回车卸载
[root@iZ8vb8avlmvb451wmm14rqZ ~]# yum remove mysql-common.x86_64
中途会让你输入y以确认,一个一个地卸载也是可以的,名称按上面的一字不落地写上去就会卸载
查看卸载结果
[root@iZ8vb8avlmvb451wmm14rqZ ~]# rpm -qa |grep -i mysql
mysql-community-release-el7-5.noarch
只剩下7的了。把这个也卸载了。
查看yum下的可安装列表
[root@iZ8vb8avlmvb451wmm14rqZ ~]# yum repolist all|grep mysql
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community - Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - Source disabled
mysql56-community MySQL 5.6 Community Server enabled
mysql56-community-source MySQL 5.6 Community Server - Source disabled
mysql57-community-dmr MySQL 5.7 Community Server Developmen disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Developmen disabled
enabled表示可以安装,选择要安装的版本,比如要安装5.7,把5.6给灭掉代码如下
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
安装后不成功,又卸载了一次,直到命令yum repolist all|grep mysql 结果不空为止
查看mysql目录:find / -name mysql
输出啥一个个复制路径下来前面加rm -rf 路径 直接全删掉
查找目录如下:
/var/lib/mysql /var/lib/mysql/mysql
删除对应的mysql目录:
rm -rf /var/lib/mysql
rm -rf /var/log/mysqld.log
4.1.下载MySQL官方的Yum Repository(Mysql5.7)
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
4.2.安装Yum Repository
yum -y install mysql57-community-release-el7-10.noarch.rpm
查看版本信息:
[root@iZ8vb8avlmvb451wmm14rqZ ~]# yum repolist all|grep mysql
我们可以看到有5.7也有8.0的,但一定要把8的版本--disable掉,才执行下面命令
4.3.Yum安装MySQL
yum install mysql-community-server --nogpgcheck --绕过校验 不然会安装报错
1.启动命令 systemctl start mysqld.service
2.重启命令 systemctl restart mysqld.service
3.关闭命令 systemctl stop mysqld.service
4.查看状态 systemctl status mysqld.service
另一种办法在终端命令行中输入以下命令关闭mysql服务。
service mysqld stop #关闭mmysql服务
#或/etc/init.d/mysqld stop
service mysqld star #启动mysql服务
/etc/init.d/mysqld start #启动mysql服务
localhost:后面的就是密码,我的密码第一个字母是个空格,真是操蛋,输入了十来次也没成功,
A temporary password is generated for root@localhost: :sgv)qZtQ3#b
直接用工具打开mysqld.log,复制密码
mysql -u root -p
【alter user 'root'@'localhost' identified by 'your new password'】
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
刷新一下:FLUSH PRIVILEGES;
update user set host='%' where user='root';
验证是否修改成功
select host,user from mysql.user;
刷新一下:FLUSH PRIVILEGES;
创建用户
create user ‘username’@’%’ identified by ‘password’;
//在username和password填写自己的账户名称和密码, %代表支持远程连接
刷新一下:FLUSH PRIVILEGES;
systemctl list-unit-files | grep mysql
不是的话设置为开机启动
systemctl enable mysqld.service
开机启动应该是如下标志
mysqld是mysql的守护进程 d是daemon
下载mysql5.7的tar版本
从官网下载
MySQL :: Download MySQL Community Server
这种安装相对复杂,下载文件耗时长,配置起来也麻烦,具体参考