阅读789 返回首页    go 阿里云 go 技术社区[云栖]


Mysql权限命令

在网上搜索了半天,最后发现设置权限命令都不能用。检测了半天发现  命令字符 写错了。我靠。网上大部分都是错的。。

upkiller 为密码

1,查看mysql状态:

mysqladmin -h localhost -u root -pupkiller satus 

2,更改root密码:
mysqladmin -h localhost -u root -pupkiller password upkiller

3,导入一个sql文件到数据库:(恢复一个数据库)
mysql -h localhost -u root -pupkiller cacti < cacti.sql //把cacti.sql文件导入到cacti数据库或者使用source命令导入

4,导出一个数据库:
mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -h localhost -u root -pupkiller mysql > mysql.sql

5,导出一个表:
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名
mysqldump -u root -pupkiller mysql user > user.sql

6,导出一个数据库结构:
mysqldump -u 用户名 -p -d --add-drop-table 数据库名 > 导出的文件名
-d 没有数据 --add-drop-table 在每个create语句之前增加一个drop table
mysqldump -h localhost -u root -pupkiller -d --add-drop-table mysql > table.sql


7,增加一个用户对数据库所有权(该用户对该数据库的权限,即数据库所有者):
create database cacti;
grant all on cacti.* to cacti@localhost identified by 'upkiller'; //对该数据库全部权限
flush privileges; //立即生效
//部份权限,insert,select,delete,update,drop,create
grant insert,select,delete,update on cacti.* to cacti@localhost identified by 'upkiller';

//创建一个超级用户test1
grant allprivileges on *.* to test1@localhost identified by '123456' with grant option;

//创建一个只能查询的用户test2
grant select on *.* to test2@localhost identified by '9876543';

8,删除一个用户upkiller对数据库的权限:
revoke all on *.* from upkiller@localhost;   #注意只是撤消权限,还需要删除用户
user mysql;                                  #删除用户
delete from user where user='upkiller' and host='localhost';
flush privileges;

9,修改mysql数据库名称:

改库名好像没有这个命令,可以把原库倒出来然后恢复到新库里


10,改变表名
Alter TABLE `原表名` RENAME TO `新表名`;

11,web与数据库分离时加快连接速度:

vi /etc/my.cnf
在mysqld段加入:skip-name-resolve


12,让mysql不区分表名的大小写:

在mysqld段加入:lower_case_table_names=1 

最后更新:2017-04-02 17:09:28

  上一篇:go ListView滚动翻页 异步加载
  下一篇:go 在Android中支持表情