前提是你用无密码的进入创建一个数据库,然后使用该数据库后
(设置所有ip访问)
use mysql;
GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
(设置本地访问)
use mysql;
grant all on *.* to 'root'@'localhost' IDENTIFIED BY 'your password' with grant option;
当然也可以 update user set password='your password' where user='root';