การเปลี่ยน password ของ root ใน MySQL

เราสามารถตั้งค่า password ของ root ได้ดังนี้

$ mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 146 to server version: 5.0.26-standard
 
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> SET PASSWORD FOR root@localhost=PASSWORD(’newpassword’);
Query OK, 0 rows affected (0.06 sec)
mysql>

จากตัวอย่างข้างต้น เราได้ตั้ง password ของ root เป็น newpassword หากตั้งค่าไม่ได้ให้เพิ่ม -p เข้าไปเพื่อให้สามารถใส่ password ได้ ดังนี้

$ mysql -u root mysql
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)
$ mysql -u root -p mysql
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 146 to server version: 5.0.26-standard
 
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>

ที่มา: NetAdminTools

No votes yet