Home > Database > Mysql Tutorial > 初始化MySQL用户(删除匿名用户)_MySQL

初始化MySQL用户(删除匿名用户)_MySQL

WBOY
Release: 2016-05-27 13:45:33
Original
1086 people have browsed it

安装完MySQL后,系统默认会创建一个不需要密码的root用户,和一个无用户名无密码的匿名用户(Anonymous Account)。进行下面的初始化操作以合理授权,增强安全。

设置root密码先以root身份登入mysql -u root,设置root密码:

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';

如果提示报错,如:

代码如下:


mysql ERROR 1396 (HY000): Operation DROP USER failed for ''@'localhost'

则是因为*nix系统下,需要以'用户'@'hostname'的方式删除。方法如下:

代码如下:


# 先查明确切的hostname
select user,host from mysql.user;
# 找出其中user为空的host名
# 删除此匿名用户
DROP USER ''@'上一步找到的hostname';

via:

设置密码:https://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html
创建用户:https://dev.mysql.com/doc/refman/5.1/en/adding-users.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template