官网下载地址:https://dev.mysql.com/downloads/mysql/
1、 yum remove mysql mysql-server mysql-libs mysql-server;
2、查看系统中是否以rpm包安装的mysql
rpm -qa | grep -i mysql
如果有执行卸载mysql
rpm -e mysql-community-common.xxx
3、whereis mysql 或者 find / -name mysql
清空相关mysql的所有目录以及文件 rm -rf /usr/share/mysql
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql
rm -rf /usr/my.cnf
按顺序安装
rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.13-1.el7.x86_64.rpm
mysqld --initialize --console
mysql8自动创建mysql组和用户
chown -R mysql:mysql /var/lib/mysql/
systemctl start mysqld
mysql_secure_installation
service mysqld restart
1、rpm -ivh ***.rpm 安装时,安装不上
原因:与默认mariaDB冲突。
解决方法:卸载maridb(通过rpm -qa | grep mariadb查找)
卸载:rpm -e **** --force --nodeps
2、缺少依赖包libaio
直接实用yum包管理工具安装即可:yum install libaio
3、mysql -u root -p登录时报错
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
直接重置密码
停mysql服务:service mysqld stop
修改配置文件免密码登录:vi /etc/my.cnf
在[mysqld]最后加上如下语句(skip-grant-tables),并保存退出
启动mysql服务:service mysqld start
免密登录mysql,直接命令行输入:
mysql
//或者 mysql -u root -p //password直接回车
选择database,并查看root用户信息:
use mysql;
select host, user, authentication_string, plugin from user;
如果当前root用户authentication_string字段下有内容,先将其设置为空;
update user set authentication_string='' where user='root';
退出mysql, 删除/etc/my.cnf文件最后的 skip-grant-tables 重启mysql服务;
使用root用户进行登录,因为上面设置了authentication_string为空,所以可以免密码登录;
mysql -u root -p //passwrod:直接回车;
使用ALTER修改root用户密码;
ALTER user 'root'@'localhost' IDENTIFIED BY 'rootPwd' ;
至此修改成功; 从新使用用户名密码登录即可;