1.下载mysql
https://dev.mysql.com/downloads/mysql/
操作系统选RedHat
依次下载四个安装包
mysql-community-common-5.7.33-1.el7.x86_64.rpm
mysql-community-libs-5.7.33-1.el7.x86_64.rpm
mysql-community-server-5.7.33-1.el7.x86_64.rpm
mysql-community-client-5.7.33-1.el7.x86_64.rpm
2.移除已安装mysql,mariadb
centos7默认安装mariadb
rpm查看是否安装过mysql:
rpm -qa|grep -i mysql
rpm -qa|grep -i mariadb
移除安装过的mariadb和mysql
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
whereis mysql
find / -name mysql
rm -rf 删除
查看mysql是否启动:ps -ef |grep mysql
3.Xshell使用rz命令上传msyql文件并安装
下载地址:https://dev.mysql.com/downloads/mysql/
mysql-community-common-5.7.33-1.el7.x86_64.rpm
mysql-community-libs-5.7.33-1.el7.x86_64.rpm
mysql-community-client-5.7.33-1.el7.x86_64.rpm
mysql-community-server-5.7.33-1.el7.x86_64.rpm
如下命令依次安装以上4个文件
rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.33-1.el7.x86_64.rp
4.启动mysql
service mysqld start
systemctl start mysqld.service
5.连接msyql失败问题
mysql -uroot -p
登录失败:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决办法:
vim /etc/my.cnf
[mysqld]添加skip-grant-tables,这样再次登陆就不用输入密码,直接回车就进入数据库了。
重启服务:service mysqld restart
连接mysql:mysql -uroot -p
输入密码直接回车,进入mysql
6.设置数据库密码
use mysql;
show tables;
查看user表结构:desc user;
Host存的是允许访问的主机
User是登录名
authentication_string是登录密码,老版本用的字段是password
修改密码:update user set authentication_string=password('123456') where user='root';
退出mysql:quit;
重启服务:service mysqld restart