yum安裝mysql後root使用者的臨時密碼

來源:互聯網
上載者:User

標籤:通過   cut   指定   class   flush   tar   database   配置   方便   

1.查看root使用者臨時隨機密碼

yum 安裝mysql後,無法通過空密碼登入資料庫,如下:

1 [[email protected]123 mysql]# mysql -u root -p2 Enter password: 3 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

 

尋找後,原來為了增加資料庫的安全性,在安裝時會為root使用者產生一個臨時的隨機密碼,存放在/var/log/mysqld.log 中。root使用者的臨時密碼查看方法如下(紅色標註部分就是其臨時密碼):

1 [[email protected]123 mysql]# grep ‘password‘ /var/log/mysqld.log |head -n 12 2017-06-17T02:01:01.026946Z 1 [Note] A temporary password is generated for [email protected]: XqWlxlV3p.a83 [[email protected] mysql]# mysql -u root -p4 Enter password: 5 Welcome to the MySQL monitor.  Commands end with ; or \g.6 Your MySQL connection id is 311697 Server version: 5.7.18
2.修改root使用者密碼

使用臨時密碼登入資料庫後,mysql會提示你修改臨時密碼,否則無法使用,如下:

1 mysql> show databases;2 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

使用ALTER USER命令修改使用者:(本人未使用,在此附上連結,以便以後方便查看)

http://blog.csdn.net/ziwen00/article/details/8460754

ALTER USER格式如下:

  alter user [使用者名稱] indentified by [新密碼];

修改root的密碼,使用了如下方法,三步完成密碼密碼的更改:

mysql> set password(‘123455‘);       #紅色部分是新密碼
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
#提示資訊:密碼不適應當前的密碼原則的要求,具體的原理不在這裡闡述,可以參見安裝MySQL5.6建立使用者並建立密碼時總是提示密碼不符合要求:ERROR 1819 (HY000): Your password does NOT..解決
#解決方案:這裡我們可以參考為root使用者產生的密碼的格式【大小寫字母+數字——特殊符號】
mysql> ALTER USER ‘root‘@‘localhost‘ PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

使用新密碼可以登入到資料庫。

3.設定資料庫的遠端連線
1 mysql>CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘您的密碼‘;2 # 增加root使用者指定可以任意IP登入,如果想限制只能讓指定IP登入請把%替換成IP地址3    4 mysql>GRANT ALL PRIVILEGES ON * . * TO ‘root‘@‘%‘ IDENTIFIED BY ‘你的密碼‘ WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;5 #給新添加的root增加許可權

 

 

 

  

 

yum安裝mysql後root使用者的臨時密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.