首次在centos下安裝MySQL,客戶端鏈接mysql時報錯:

mysql版本:5.7.13 首次在centos下安裝MySQL,客戶端鏈接mysql時報錯: [plain] view plain copy 在CODE上查看代碼片派生到個人代碼片 [root@localhost opt]# /usr/bin/mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)mysql

【解決】: 一、找到密碼 [plain] view plain copy 在CODE上查看代碼片派生到個人代碼片 [root@localhost opt]# cat /var/log/mysqld.log | grep password
2016-07-16T05:01:47.771362Z 1 [Note] A temporary password is generated for root@localhost: q.)aq!YaH6y-
2016-07-16T05:02:32.000199Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-07-16T05:02:39.063852Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)sql

二、從新鏈接mysql: [plain] view plain copy 在CODE上查看代碼片派生到個人代碼片 [root@zzs171 opt]# /usr/bin/mysql -u root -p
Enter password:
輸入上面找到的密碼,便可進入mysql客戶端鏈接。centos

三、修改mysql的root的密碼: 進入mysql客戶端以後,show databases; 會提醒先修改密碼: [plain] view plain copy 在CODE上查看代碼片派生到個人代碼片 mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
設置密碼,如下兩種方式都可: [plain] view plain copy 在CODE上查看代碼片派生到個人代碼片 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Mysqlpassw0rd.');ide

alter user 'root'@'localhost' identified by 'Mysqlpassw0rd.';ui

OK,至此設置成功。注意mysql有密碼複雜度的限制。密碼太簡單會提示: [plain] view plain copy 在CODE上查看代碼片派生到個人代碼片 mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsthis

相關文章
相關標籤/搜索