MySQL基础 - 权限配置

为数据库创建特定的用户和密码

mysql>grant all privileges on <database>.* to '<username>'@'localhost' identified by '<password>';
mysql>grant all privileges on <database>.* to '<username>'@'localhost' identified by '<password>';

举例,为icebug用户创建专属的数据库icebug_db,且密码为icebug_passwd

mysql>create database icebug_db;
mysql>grant all privileges on icebug_db.* to 'icebug'@'localhost' identified by 'icebug_passwd';     # 目的是本地可访问
mysql>grant all privileges on icebug_db.* to 'icebug'@'%' identified by 'icebug_passwd';             # 目的是远程主机可以访问

创建好了之后就可以直接通过用户icebug和密码icebug_passwd登陆数据库系统了,注意通过icebug账号和icebug_passwd登陆之后只能看到数据自己的数据库,并不能看到别人的数据库,这也是为什么要为特定数据库创建特定账号和密码了,千万注意不要人手一个root账号和密码.....

登陆

icebug@localhost:~$ mysql -uicebug -picebug_passwd

这样就可以登陆icebug的数据库了~

tips:

最好不要这样直接把密码放到命令行里一块敲,不然很容易在bash history中留下密码痕迹,出于安全考虑还是通过mysql -uicebug -p之后再敲入密码为好。

posted @ 2016-11-28 22:15  乔栋  阅读(208)  评论(0编辑  收藏  举报