一、mysql用户管理
grant all on *.* to ‘user1‘@‘127.0.0.1’ identified by ‘mimA123‘; 创建user1用户
使用user1登录
/usr/local/mysql/bin/mysql -uuser1 -pmimA123 -h127.0.0.1
变为localhost,不加-h也能登录
mysql> grant all on *.* to ‘user1‘@‘localhost‘ identified by ‘mimA123‘;
[[email protected] ~]# /usr/local/mysql/bin/mysql -uuser1 -pmimA123
grant SELECT,UPDATE,INSERT on db1.* to‘user1‘@‘192.168.1.101‘ identified by ‘mimA123‘; 授权
grant all on db1.* to ‘user2‘@‘%‘ identified by ‘mimA123‘; 给任意ip授权,任何ip用%代替
show grants;
show grants for [email protected].1; 查看指定用户授权
二、常用sql语句
登录mysql切换到db1库
select count(*) from mysql.user; 查询
select * from mysql.db;
mysql库里边使用到的ENGINR是MyISAM,能够自动帮助统计有多少行
自己创建的库ENGINE是InnoDB
select db from mysql.db;
select db,user from mysql.db;
select * from mysql.db where host like ‘192.168.%‘;
insert into db1.t1 values (1, ‘abc‘); 插入
update db1.t1 set name=‘aaa‘ where id=1; 更改表的一行
删除数据
delete from db1.t1 where id=1;
truncate table db1.t1; 清空数据表,表格还在
drop table db1.t1; 删除表,所有表格数据都删除了
drop database db1; 删除数据库
三、mysql数据库备份恢复
创建一个新的数据库mysql2
/usr/local/mysql/bin/mysql -uroot -e "create database mysql2"
备份库 mysqldump -uroot -pmimA123 mysql > /tmp/mysql.sql
恢复库 mysql -uroot -pmimA123 mysql < /tmp/mysql.sql
备份表 mysqldump -uroot -pmimA123 mysql user > /tmp/user.sql
恢复表 mysql -uroot -pmimA123 mysql < /tmp/user.sql
备份所有库 mysqldump -uroot -p -A > /tmp/123.sql
只备份表结构 mysqldump -uroot -pmimA123 -d mysql > /tmp/mysql.sql
原文地址:https://www.cnblogs.com/davery/p/8977937.html