标签:mysql
一、登录
绝对路径登录,终端中命令:/usr/local/mysql/bin/mysql -u root -p
更改mysql root账户密码 终端中输入命令:/usr/local/mysql/bin/mysqladmin -u root password 新密码
二、创建用户
@>mysql -u root -p
@>密码
mysql> insert into mysql.user(Host,User,Password) values("localhost","changyou",password("changyou"));
刷新系统权限表
mysql>flush privileges;
这样就创建了一个名为:changyou 密码为:changyou 的用户。
然后登录一下。
mysql>exit;
@>mysql -u changyou -p
@>输入密码
mysql>登录成功
@>mysql -u root -p
@>密码
mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost";
mysql>flush privileges;
//删除用户的数据库
mysql>drop database phplampDB;
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password(‘新密码‘) where User="phplamp" and Host="localhost";
mysql>flush privileges;
三、为用户授权
1.
grant all privileges on . to ‘changyou’@’%’ with grant option ;
grant all privileges on . to ‘changyou’@’%’ identified by ‘changyou’;
flush privileges;
2.
grant all privileges on . to ‘user’@’localhost’ with grant option;
grant all privileges on . to ‘user’@’localhost’ identified by ‘123456′;
flush privileges;
四、为用户创建数据库
登录MYSQL(有ROOT权限)。我里以ROOT身份登录.
@>mysql -u root -p
@>密码
首先为用户创建一个数据库(changyouDB)
mysql>create database changyouDB;
授权changyou用户拥有changyouDB数据库的所有权限。
grant all privileges on changyouDB.* to changyou@localhost identified by ‘changyou‘;
刷新系统权限表
mysql>flush privileges;
mysql>其它操作
如果想指定部分权限给一用户,可以这样来写:
mysql>grant select,update on changyouDB.* to changyou@localhost identified by ‘changyou‘;
//刷新系统权限表。
mysql>flush privileges;
五、操作数据库
标签:mysql
原文地址:http://blog.csdn.net/leochang130731/article/details/44518665