一 安装前准备
(1)卸载虚拟机自带的mysql相关包
rpm -qa | grep mysql
rpm -e --nodeps 名称 卸载
查询所有Mysql对应的文件夹
# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
删除相关目录或文件
rm -rf /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
检查mysql用户组和用户是否存在
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
(2)从官网下载是用于Linux的Mysql安装包
下载安装包或者直接下载
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
更新仓库信息
yum clean all&&yum repolist
安装
[root@localhost yum.repos.d]# yum list | grep mysql-com
mysql-community-client.x86_64 5.6.49-2.el6 @mysql56-community
mysql-community-common.x86_64 5.6.49-2.el6 @mysql56-community
mysql-community-libs.x86_64 5.6.49-2.el6 @mysql56-community
mysql-community-libs-compat.x86_64 5.6.49-2.el6 @mysql56-community
mysql-community-server.x86_64 5.6.49-2.el6 @mysql56-community
mysql-community-bench.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-client.i686 5.6.51-2.el7 mysql56-community
mysql-community-client.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-common.i686 5.6.51-2.el7 mysql56-community
mysql-community-common.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-devel.i686 5.6.51-2.el7 mysql56-community
mysql-community-devel.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-embedded.i686 5.6.51-2.el7 mysql56-community
mysql-community-embedded.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-embedded-devel.i686 5.6.51-2.el7 mysql56-community
mysql-community-embedded-devel.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-libs.i686 5.6.51-2.el7 mysql56-community
mysql-community-libs.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-release.noarch el7-5 mysql-connectors-community
mysql-community-server.x86_64 5.6.51-2.el7 mysql56-community
mysql-community-test.x86_64 5.6.51-2.el7 mysql56-community
根据需要安装
yum install mysql-community-server.x86_64 5.6.51-2.el7 -y
初始化
systemctl start mysqld
查看目录有没有生成
cd /var/lib/mysql
过滤mysql密码
grep ‘password‘ /var/log/mysqld.log
登录数据库
mysql -uroot -p‘初始化密码‘
update user set password=password(“111111”) where user=‘root’;
修改用户密码(此处根据需要操作)
set password for‘username‘@‘host‘ = password(‘newpassword‘); //设置指定用户的密码
set password = password(‘newpassword‘); // 设置当前登录用户的密码