1,新建用户
登录mysql的root用户
$> mysql -u root -p
$> root密码
新建用户名为tester,密码为123456的用户,localhost限制只能本地访问,结尾分号是必须的。
mysql> insert into mysql.user(Host,User,Password) values('localhost','tester',password('123465'));
刷新
mysql> flush privileges;
退出mysql ,切换新用户
mysql> exit;
$> mysql -u tester -p
$ > 123456
登陆成功
在添加新用户时容易出现以下错误!!
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
此时使用以下命令创建新用户。账户名tester ,密码123456。
grant usage on *.* to 'tester'@'localhost' identified by '123465' with grant option;
使用localhost,限制只能本地访问数据库,将其改为‘%’后可远程访问。
grant usage on *.* to 'tester'@'%' identified by '123465' with grant option;
2,配置权限
新建用户没有数据库的权限,这里我们新建一个test数据库,并赋予tester用户所有权限。
登录root用户
$> mysql -u root -p
$> root密码
创建一个新数据库 test:
mysql> create database test;
赋予用户tester 所有test数据库操作权限:
mysql> grant all privileges on test.* to tester@localhost identified by '123456';