默认情况下,有两个用户,root用户和一个匿名用户。两个用户密码都是空。登陆如下: # mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.5.10-log Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 默认情况是不安全的,因此我们对其进行更改。首先设置root用户的密码: mysql>use mysql; mysql>update user set password=password('123456') where user='root'; mysql>flush privileges; 注:flush privileges 是刷新内存授权表,否则用的还是缓冲的口令。 查看是否设置成功,重新登陆,如下: # mysql -u root -p 输入密码,进入则成功。 然后,删除匿名用户,如下: mysql>delete from user where user=''; 新建用户,并为其设置权限。 1.直接在mysql.user中直接插入user,password。 mysql>insert into user(user,password) values('yangyang',password('yangyang')); mysql>flush privileges; 2.mysql>GRANT 权限1,2,3... ON 数据库.表名 TO 用户名@用户地址 IDENTIFIED BY 用户密码 WITH GRANT OPTION。 权限:select,insert,delete,update,create,drop,index,grant,alter,references,reload,shutdown,process,file等。all privileges 或 all 表示所有权限。 数据库.表名: *.*表示所有数据库和表。 用户地址:localhost,ip,机器名字,域名。%表示任何地址连接。 用户密码:不能为空。 例子: mysql>GRANT ALL PRIVILEGES ON *.* TO monty@"%"IDENTIFIED BY 'something' WITH GRANT OPTION; mysql>flush privileges;注:该用户拥有所有权限,相当与root用户。 删除用户 mysql>DELETE FROM user WHERE user='monty' ; mysql>flush privileges; 退出用户 mysql>exit 转载请保留固定链接: https://linuxeye.com/database/993.html |