1、新建用户并授权1
2
3insert into mysql.user(Host,User,Password) values("Host","User",password('password'));
grant all privileges on *.* to User@Host identified by 'password';
flush privileges;
2、新建数据库同时指定默认编码格式:1
2CREATE DATABASE IF NOT EXISTS my_testDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci; utf8编码
create database yourdb DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; gbk编码
3、查看用户权限1
show grants for 'User'@'Host';
4、删除用户1
2Delete FROM user Where User='test' and Host='localhost';
flush privileges;
5、给一个用户授权1
2grant all on databases.* to ops;
flush privileges;
6、收回一个用户权限1
2revoke all on databases.* from ops; //如果权限不存在会报错
flush privileges;
参考url http://www.cnblogs.com/fslnet/p/3143344.html
7、设置主从复制命令1
2
3
4
5GRANT REPLICATION SLAVE,FILE ON *.* TO 'replnew'@'Host' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
stop slave;
CHANGE MASTER TO MASTER_HOST='Host',MASTER_USER='replnew',MASTER_PASSWORD='password',MASTER_LOG_FILE='mysql-bin.***',MASTER_LOG_POS=number;
8、innodb恢复全备命令1
2innobackupex --defaults-file=/etc/my.cnf.d/server.cnf --use-memory=4G --apply-log /data/mysql_xtrabackup/full
innobackupex --defaults-file=/etc/my.cnf.d/server.cnf --use-memory=4G --copy-back /data/mysql_xtrabackup/full
9、修改root密码1
2UPDATE user SET Password = PASSWORD('password') WHERE user = 'root';
FLUSH PRIVILEGES;
10、mysqldump导出完整数据,加入-R –single-transaction参数1
mysqldump -u$user -p$pass -R --single-transaction database > database-`date +%F-%T`.sql
11、生成一个MD5加密的密码,这里密码设置的是redhat1
2# echo -n redhat | openssl md5
(stdin)= e2798af12a7a0f4f70b4d69efbc25f4d
---本文结束感谢您的阅读。微信扫描二维码,关注我的公众号---
本文链接: https://www.yp14.cn/2016/07/06/Mysql常用命令/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!