1.清理掉之前安装过的mysql (如果之前没有安装过mysql请忽略此步骤)
mysql rpm -qa | grep mysql 命令检查系统是否装有mysql
rpm -qa | grep mysql mysql-libs-5.1.52-1.el6_0.1.x86_64
yum remove mysql-libs-5.1.52-1.el6_0.1.x86_64
rm -fr /var/lib/mysql/* rm /var/lock/subsys/mysqld killall mysqld
2.yum源安装MYSQL
如果是linux6则下载 wget https://repo.mysql.com//mysql80-community-release-el6-1.noarch.rpm
如果是linux7则下载 wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
如果是linux8则下载 wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
然后
如果是linux6则执行 rpm localinstall mysql80-community-release-el6-1.noarch.rpm
如果是linux7则执行 yum localinstall mysql80-community-release-el7-3.noarch.rpm
如果是linux8则执行 yum localinstall mysql80-community-release-el7-3.noarch.rpm
查看yum存储仓库中的mysql
# yum repolist all | grep mysql
安装mysql
yum install mysql-community-server
如果上面的命令报错,可能是因为你之前安装过,需要执行 下面的命令后再重新执行
yum clean all
yum makecache
查看mysql版本
mysql --version
3.启动MySQL
/etc/init.d/mysqld start 或 service mysqld start
/etc/init.d/mysqld restart 重启 或 service mysqld restart 重启
service mysqld status 查看是否启动
4.如果启动成功请忽略,如果启动mysql报错 mysqld:unrecognized service
可能是mysql-server没有安装
rpm -q mysql
安装mysql的server端
yum install mysql-server
然后再输入/etc/init.d/mysqld start 启动成功
5.登录前先找到默认登陆密码
grep "password" /var/log/mysqld.log
6.登陆
mysql -u root -p
然后输入默认的登陆密码
7.修改密码,mysql8.0以上密码策略限制必须要大小字母写加数字特殊符号
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码要复杂';
设置允许远程机器连接 修改root的host为%
update user set Host='%' where User='root';
刷新系统权限表
flush privileges;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '数据库密码';
flush privileges;
设置安全组规则:
(觉得图片看不清,请Ctrl+鼠标滚动)
然后navicat数据用户名和密码 就可以登录了
重置密码参考https://blog.csdn.net/zzzgd_666/article/details/81458630