mysql -u root -p -h myhost.com mysql -u root -p -h 192.168.1.101 mysql -u root -p mysql -u myname -p
设置密码
方法一:
1 2 3
update User set Password=PASSWORD('<password>') where User='<username>'; # 设置完毕刷新权限 FLUSH PRIVILEGES;
例:
1 2
update User set Password=PASSWORD('woshimima') where User='root'; FLUSH PRIVILEGES;
方法二:
1 2 3 4
# 修改所有用户的密码,前提是拥有修改密码的权限 set password for '<usernmae>'@'<hostname|hostip>' = password('<password>'); # 修改当前登录用户密码 set password = password('<password>');
查看MySQL默认编码
1
show [global] variables like 'char%';
查看MySQL是否区分大小写
1
show variables like '%case%';
修改数据库编码
1
alter database <databasename> CHARACTER SET <encoding>;
例:
1
alter database mydb CHARACTER SET utf8;
创建数据库
1
create database <databasename>;
例:
1
create database mydb;
新增用户
1
create user '<username>'@'<hostname|hostip>' identified by '<password>';
create user 'myname'@'myclienthost.com' identified by 'woshimima'; create user 'myname1'@'192.168.1.102' identified by 'woshimima1'; create user 'myname2'@'%' identified by 'woshimima2'; create user 'myname3'@'%' identified by '';
删除用户
1
drop user '<username>'@'<hostname|hostip>';
例:
1 2
drop user 'myname'@'myclienthost.com'; drop user 'myname'@'%';
授权用户权限
1
grant <priviliege> on <databasename>.<tablename> to '<username>'@'<hostname|hostip>';
grant all on mydb.mytable to 'myname'@'myclienthost.com'; grant all on *.* to 'myname'@'%'; grant select on mydb.mytable to 'myname'@'myclienthost.com';
以上命令授权的用户不能给其他用户授权,如果想让该用户可以授权,用以下命令:
1
grant <priviliege> on <databasename>.<tablename> to '<username>'@'<hostname|hostip>' with grant option;
撤销用户权限
1
revoke <priviliege> on <databasename>.<tablename> from '<username>'@'<hostname|hostip>';
例:
1 2 3
revoke all on mydb.mytable from 'myname'@'myclienthost.com'; revoke all on *.* from 'myname'@'%'; revoke select on mydb.mytable from 'myname'@'myclienthost.com';
查看用户权限
1
show grants for '<username>'@'<hostname|hostip>';
例:
1 2
show grants for 'myname'@'myclienthost.com'; show grants for 'myname'@'%';