1)mysql 安装
1.安装MySQL YUM资源库
[[email protected] ~]# yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2.此时可以使用以下命令搜索到所需安装mysql
[[email protected] ~]# yum search mysql
3.安装
[[email protected] ~]# yum -y install mysql-community-server.x86_64
4.启动数据库
[[email protected] ~]#systemctl start mysqld(centos7上使用systemctl,其他版本的centos可能使用service,我一直用的centos7)
5.设置开启自启动
[[email protected] ~]#systemctl enable mysqld
6.安装完成
2)mysql初始密码问题(适用于mysql5.7以上版本)
1.由于我上一个数据库卸载没完全的问题,所以cat /var/log/mysqld.log|grep temporary并不能获得初始密码
[[email protected] ~]# cat /var/log/mysqld.log|grep temporary
2019-12-07T01:23:03.644746Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2.删除残留数据
[[email protected] ~]# rm -rf /var/lib/mysql
3.重启
[[email protected] ~]# systemctl restart mysqld
4.再获得初始密码
[[email protected] ~]# cat /var/log/mysqld.log|grep temporary
2019-12-07T01:23:03.644746Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-12-07T01:29:08.103192Z 1 [Note] A temporary password is generated for [email protected]: *oEsYdO_x9fj
2019-12-07T01:29:10.501031Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
此时可以得到初始密码为*oEsYdO_x9fj
5.进入数据库
mysql -uroot -p*oEsYdO_x9fj
6.重设密码
mysql> set password=‘NewPassword‘;
或者
mysql> ALTER user ‘root‘@‘localhost‘ IDENTIFIED BY ‘NewPassword‘;
7.完成。
原文地址:https://www.cnblogs.com/lyz-2019-12-05/p/12000737.html