1.检查是否安装了mysql
rpm -qa|grep -i mysql
centos7默认是安装的mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb
2.卸载默认安装的mysql
rpm -e --nodeps mysql-libs-XX
yum remove mysql mysql-server mysql-libs mysql-server;
rpm -e --nodeps pcp-pmda-mysql-3.10.6-2.el7.x86_64
3.安装mysql,上传安装包
这里面有六个rpm包,下这一个就够了
tar -xvf MySQL-server-5.6.43-1.el7.x86_64.rpm-bundle.tar
六个只需要安装server和client就可以了
4.安装server
rpm -ivh MySQL-server-5.6.43-1.el7.x86_64.rpm
如果这一步报错,缺少依赖可以不用管,使用下面的命令】
rpm -ivh MySQL-server-5.6.43-1.el7.x86_64.rpm --force --nodeps
5.安装client
rpm -ivh MySQL-client-5.6.43-1.el7.x86_64.rpm
同样安装报错,缺少依赖
rpm -ivh MySQL-client-5.6.43-1.el7.x86_64.rpm --force --nodeps
6.启动mysql
service mysql start
7.设置密码
初始密码在 /root/.mysql_secret 这个文件里
cat /root/.mysql_secret
登陆
mysql -uroot -p初始密码
修改密码(root 是新密码)
set PASSWORD=PASSWORD('root');
8.赋权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'hadoop02' IDENTIFIED BY 'root' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES;
查看user表的登陆权限
select host, user from user;
%可以任意ip登陆,不然除了本机连接会报错