1. 安装Mysql8
1.下载 安装Mysql yum Repository
wget https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm #下载 yum localinstall mysql80-community-release-el8-4.noarch.rpm #安装 yum repolist all | grep mysql #查看可安装mysql版本列表,如果版本不对,修改/etc/yum.repos.d/mysql-community.repo文件 yum module disable mysql #安装 vi /etc/yum.repos.d/mysql-community.repo #修改默认的mysql服务器安装版本,这里选择8.0
2.安装、启动、关闭、重启Mysql,并查询mysql状态
yum install mysql-community-server #安装mysql systemctl status mysqld #查看mysql状态 systemctl start mysqld #启动mysql systemctl stop mysqld #关闭mysql systemctl restart mysqld #重启mysql
3.设置mysql密码
grep 'temporary password' /var/log/mysqld.log #查看初始密码 mysql -u root -p #初始密码登陆mysql控制台,在控制台中依次执行以下sql,修改密码 mysql>alter user 'root'@'localhost' identified by 'newpassword'; #修改密码 mysql> flush privileges; #刷新数据库 mysql> quit #退出mysql控制台 vim /etc/my.cnf #修改配置文件,删除[mysqld]后面的免密登陆属性“skip-grant-tables” systemctl restart mysqld #重启mysql
3.允许客户端远程连接
grant all privileges on *.* to 'root'@'localhost' with grant option; #先确保自己有授权权限 flush privileges;#刷新系统 use mysql; #切换到mysql数据库 create user 'root'@'%' identified by 'newpassword'; #创建新用户,这里的localhost换成%通配符,匹配所有host grant all on *.* to 'root'@'%'; #放开客户端连接 flush privileges;#刷新系统
4.设置mysql编码为utf8mb4,支持emoji表情文字等多字节数据
vim /etc/my.cnf #修改配置文件,增加以下内容 ###################分割线######################## [client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' ###################分割线######################## systemctl restart mysqld #重启mysql mysql -u root -p #登陆mysql控制台 mysql> update user set authentication_string=password('newpassword') where user='root'; #关闭mysql
2、卸载MySQL
systemctl stop mysqld #停止mysql服务
yum list installed | grep mysql #查看含有mysql的服务
yum remove mysql-community-client mysql-community-common mysql-community-server mysql-community-libs #卸载mysql相关服务
whereis mysql #将列出来的内容通过 rm 命令删除掉即可,至此,就可以将整个MySQL卸载了。