下面的所有操作建议在root权限下:
1.查看并去查依赖
rpm -qa | grep mysql
2.wget 获取rpm相应的.rpm文件
获取安装源码的方式很多,这里我就采用比较简单的一种,当然还有一种的就是直接下载
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.20-1.el6.x86_64.rp
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.20-1.el6.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.20-1.el6.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.20-1.el6.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-devel-5.7.20-1.el6.x86_64.rpm
3.按顺序安装
按照上面的顺序一个个安装rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm
...
这里就忽略不写了
如果你没有暗战顺序安装的话,它会提示你当前你安装的这个.rpm的文件依赖于哪个.rpm的文件!
这种安装方式是相互依赖的
下面是安装成功的截图
4.启动mysql
service mysqld start
5.获取mysql预装root用户的密码
grep 'temporary password' /var/log/mysqld.log
6.登录mysql系统
mysql -uroot -pn%JtA0?pyfcg
7.修改root用户密码
set password = password("Hadoop123456!")
密码太简单不符合它的安全策略(ERROR 1819 (HY000): Your password does not satisfy the current policy requirements),所以设置密码的时候需要有大小写还有特殊符号!
8.允许远程登录
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
9.测试
1.查看3306端口是否打开
[root@hadoop01 ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2948/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1646/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1897/master
tcp 0 0 :::22 :::* LISTEN 2948/sshd
tcp 0 0 ::1:631 :::* LISTEN 1646/cupsd
tcp 0 0 ::1:25 :::* LISTEN 1897/master
tcp 0 0 :::3306 :::* LISTEN 3787/mysqld
到这里mysql的rpm安装方式就成功了!恭喜你
10.设置开机自启动
[root@hadoop01 ~]# chkconfig mysqld on
[root@hadoop01 ~]# chkconfig --list | grep mysql
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
注意红色的地方,这里是
mysqld不是mysql,如果写成mysql 就会报
error reading information on service mysql: No such file or directory错误
error reading information on service mysql: No such file or directory错误
11.其他相关mysql的情况
a.查看mysql所有依赖的包 rpm -qa | grep -i mysql
[root@hadoop01 ~]# rpm -qa | grep -i mysql
mysql-community-devel-5.7.20-1.el6.x86_64
mysql-community-libs-5.7.20-1.el6.x86_64
mysql-community-client-5.7.20-1.el6.x86_64
mysql-community-server-5.7.20-1.el6.x86_64
mysql-community-common-5.7.20-1.el6.x86_64
b.查看mysql默认安装位置
[root@hadoop01 ~]# whereis mysql
mysql:
/usr/bin/mysql
/usr/lib64/mysql
/usr/include/mysql
/usr/share/mysql
/usr/share/man/man1/mysql.1.gz