1、使用yum安裝mysql后
2、初始密碼在/var/log/mysqld.log這個文件里
3、輸入命令:grep 'temporary password' /var/log/mysqld.log,可以直接獲取密碼。
(注:密碼為冒號后面的所有字符!)
如果想要更換初始密碼,可以按照下面的操作。
在/etc/my.cnf中加入如下內容:
在[mysqld]下添加skip-grant-tables,然后保存並退出
然后重啟mysql服務
systemctl restart mysqld
a、重啟以后,執行mysql命令進入mysql命令行
b、修改root用戶密碼
MySQL> update mysql.user set authentication_string=password('123456') where user='root';
MySQL> flush privileges;
MySQL> exit
c、最后把/etc/my.cnf中的skip-grant-tables注釋掉,然后重啟mysql,即:service mysqld restart
OK,下面我們就可以使用root新的密碼登錄MySQL了。