安装完MySQL后,系统默认会创建一个不需要密码的root用户,和一个无用户名无密码的匿名用户(Anonymous Account)。进行下面的初始化操作以合理授权,增强安全。
[b]设置root密码先以root身份登入mysql -u root,设置root密码:[/b]
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
创建新用户# 创建用户和设置密码
CREATE USER '新用户'@'localhost' IDENTIFIED BY '新密码';
# 对用户授权
GRANT ALL PRIVILEGES ON *.* TO '新用户'@‘localhost' WITH GRANT OPTION;
删除匿名用户DROP USER ''@'localhost';
如果提示报错,如:
[url=https://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html]https://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html[/url]
创建用户:[url=https://dev.mysql.com/doc/refman/5.1/en/adding-users.html]https://dev.mysql.com/doc/refman/5.1/en/adding-users.html[/url]