1. 安装Mysql5.7
1.下载 安装Mysql yum Repository
/etc/yum.repos.d/mysql-community.repo文件选择5.7后的版本列表,mysql57-community-dmr/x86_64的状态为enabledwget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm #下载 yum localinstall mysql80-community-release-el7-3.noarch.rpm #安装 yum repolist all | grep mysql #查看可安装mysql版本列表,如果版本不对,修改/etc/yum.repos.d/mysql-community.repo文件 vi /etc/yum.repos.d/mysql-community.repo #修改默认的mysql服务器安装版本,这里选择5.7
2.安装、启动、关闭、重启Mysql,并查询mysql状态
mysql正常hi启动后的状态显示yum install mysql-community-server #安装mysql systemctl status mysqld #查看mysql状态 systemctl start mysqld #启动mysql systemctl stop mysqld #关闭mysql systemctl restart mysqld #重启mysql
3.设置mysql密码
免密码登陆,修改此文件后要重启mysqlvim /etc/my.cn #修改配置文件,设置免密登陆属性在[mysqld]后面任意一行添加“skip-grant-tables” systemctl restart mysqld #重启mysql mysql -u root -p #空密码登陆mysql控制台,在控制台中依次执行以下sql,修改密码 mysql> update mysql.user set authentication_string=password('newpassword'); #关闭mysql mysql> flush privileges; #刷新数据库 mysql> quit #退出mysql控制台 vim /etc/my.cnf #修改配置文件,删除[mysqld]后面的免密登陆属性“skip-grant-tables” systemctl restart mysqld #重启mysql
3.允许客户端远程连接
use mysql; #切换到mysql数据库 SET PASSWORD = PASSWORD('newpassword'); #设置密码 ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; grant all on *.* to 'root'@'%' identified by 'newpassword'; #放开客户端连接 FLUSH PRIVILEGES; #刷新系统
4.设置mysql编码为utf8mb4,支持emoji表情文字等多字节数据
设置utf8mb4增加的配置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卸载了。
网友评论