mysql安装及初始密码问题

1)mysql 安装

1.安装MySQL YUM资源库

  [root@localhost ~]# yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

2.此时可以使用以下命令搜索到所需安装mysql

  [root@localhost ~]# yum search mysql

3.安装

  [root@localhost ~]# yum -y install mysql-community-server.x86_64

4.启动数据库

   [root@localhost ~]#systemctl start mysqld(centos7上使用systemctl,其他版本的centos可能使用service,我一直用的centos7)

5.设置开启自启动

  [root@localhost ~]#systemctl enable mysqld

6.安装完成

 

2)mysql初始密码问题(适用于mysql5.7以上版本)

1.由于我上一个数据库卸载没完全的问题,所以cat /var/log/mysqld.log|grep temporary并不能获得初始密码

  [root@localhost ~]# cat /var/log/mysqld.log|grep temporary

  2019-12-07T01:23:03.644746Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables

2.删除残留数据

  [root@localhost ~]# rm -rf /var/lib/mysql

3.重启

  [root@localhost ~]# systemctl restart mysqld

4.再获得初始密码

  [root@localhost ~]# 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 root@localhost: *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.完成。

posted @ 2019-12-07 09:55  gzdgz  阅读(4418)  评论(0编辑  收藏  举报