CentOS下設置MySQL的root密碼


CentOS剛裝的MySQL一般需要重設MySQL密碼,可以用以下方法重設。 
方法一、 
Js代碼  
# /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  
# /etc/init.d/mysql restart  
# mysql -uroot -p   
Enter password: <輸入新設的密碼newpassword>   
mysql>  


方法二、 
Js代碼  
直接使用/etc/mysql/debian.cnf文件中[client]節提供的用戶名和密碼:  
# mysql -udebian-sys-maint -p   
Enter password: <輸入[client]節的密碼>   
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';   
mysql> FLUSH PRIVILEGES;   
mysql> quit  
# mysql -uroot -p   
Enter password: <輸入新設的密碼newpassword>   

MySQL>  

 

支持遠程訪問:

mysql>use mysql;
mysql>update user set host = '%' where user = 'root';   --%可以改成ip或者其他
mysql>select host, user from user;    

重啟數據庫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM