centos6.9安装mysql5.7.22并设置初始密码
- 第一步:卸载以前版本或者自带lib包
[root@hdp01 apps]# rpm -qa |grep -i mysql mysql-libs-5.1.73-8.el6_8.x86_64
[root@hdp01 apps]# rpm -ev mysql-libs-* --nodeps
- 第二步:安装相关安装包
[root@hdp01 apps]# rpm -ivh mysqlPackge/mysql-community-common-5.7.22-1.el6.x86_64.rpm
[root@hdp01 apps]# rpm -ivh mysqlPackge/mysql-community-libs-5.7.22-1.el6.x86_64.rpm
[root@hdp01 apps]# rpm -ivh mysqlPackge/mysql-community-client-5.7.22-1.el6.x86_64.rpm
[root@hdp01 apps]# rpm -ivh mysqlPackge/mysql-community-client-5.7.22-1.el6.x86_64.rpm
[root@hdp01 apps]# rpm -ivh mysqlPackge/mysql-community-server-5.7.22-1.el6.x86_64.rpm
warning: mysqlPackge/mysql-community-server-5.7.22-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.22-1.el6.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.22-1.el6.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.22-1.el6.x86_64
这里缺少相关依赖,解决方法:
[root@hdp01 apps]# yum install libnuma*
[root@hdp01 apps]# rpm -ivh mysqlPackge/mysql-community-server-5.7.22-1.el6.x86_64.rpm
安装成功!
- 第三步:修改初始密码
开启mysqld服务然后关闭,才会产生随机初始密码
[root@hdp01 mysqlPackge]# service mysqld start
[root@hdp01 mysqlPackge]# service mysqld stop
[root@hdp01 mysqlPackge]# cat /var/log/mysqld.log |more 找到下面这句话,标记处就是随机初始密码
2018-04-20T06:06:15.182041Z 1 [Note] A temporary password is generated for root@localhost: oWz=Ldt2KEfg
[root@hdp01 mysqlPackge]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
这里可能会报错(没有报错请忽略),解决办法:
1)首先保证关闭mysql服务
[root@hdp01 mysqlPackge]# service mysqld status
mysqld is stopped
2) 输入
[root@hdp01 mysqlPackge]# sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[5] 5781
[root@hdp01 mysqlPackge]# 2018-04-20T06:07:57.907809Z mysqld_safe Logging to '/var/log/mysqld.log'.
2018-04-20T06:07:57.943249Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
3) 输入sudo mysql -u root mysql 进入数据库
4) mysql> update user set password_expired = "Y" where user="root";
mysql> flush privileges;
mysql> quit
[root@hdp01 mysqlPackge]# mysql -uroot -p
Enter password: 这里的密码是随机初始密码
再次进入,,成功
mysql> set password='mysql@1234'; 修改密码
mysql> grant all privileges on *.* to 'root'@'%' identified by 'mysql@1234'; 允许远程访问
[root@hdp01 mysqlPackge]# chkconfig mysqld on 设置mysql开机自启动服务