centos 6 初次安裝mysql 的密碼初始化登錄問題

最近新裝好的mysql在進入mysql工具時,老是有錯誤提示:mysql

# mysql -uroot -psql

Enter password:安全

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)工具


使用網上介紹的方法修改root用戶的密碼:ui

# mysqladmin -uroot -p password 'newpassword'spa

Enter password:rest

mysqladmin: connect to server at 'localhost' failedcode

error: 'Access denied for user 'root'@'localhost' (using password: YES)'server

注意:也能夠用  mysql安全設置 命令:ip

mysql_secure_installation

以後按以下步驟操做:

方法一:

# /etc/init.d/mysqld stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

mysql> FLUSH PRIVILEGES;

mysql> quit

注:5.7 版本的 Password 字段已經更名爲 authentication_string; 因此密碼語句須要修改成:

UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';


# /etc/init.d/mysqld restart

# mysql -uroot -p

Enter password: <輸入新設的密碼newpassword>


mysql>

# mysql -u root -p

Enter password: <輸入新設的密碼newpassword>

mysql>

問題解決了!

相關文章
相關標籤/搜索