用户管理
mysql> grant all on *.* to ‘user1‘@‘127.0.0.1‘ identified by ‘123456‘; ##创建用户并授权 mysql> grant SELECT,UPDATE,INSERT on db1.* to ‘user2‘@‘127.0.0.1‘ identified by ‘passwd‘; mysql> grant all on db1.* to ‘user3‘@‘%‘ identified by ‘passwd‘; mysql> show grants; ##查看授权 mysql> show grants for [email protected]; mysql> GRANT ALL PRIVILEGES ON *.* TO ‘user1‘@‘127.0.0.1‘ IDENTIFIED BY PASSWORD ‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘; ##创建用户
常用语句
mysql> select count(*) from mysql.user; ##查看库mysql的表user mysql> select * from mysql.db\G; ##查看表内所有内容 mysql> select db from mysql.db; ##查看db表里的db mysql> select db,user from mysql.db; ##查看db表里的db和user mysql> select * from mysql.db where host like ‘127.0.0.%‘; ##模糊查询 mysql> insert into db1.t1 values (1, ‘abc‘); ##向表内插入数据 mysql> update db1.t1 set name=‘aaa‘ where id=1; ##更改表内数据 mysql> truncate table db1.t1; ##清空表 mysql> drop table db1.t1; ##删除表 mysql> drop database db1; ##删除库
备份与恢复
[[email protected] ~]# mysqldump -uroot -p88888888 mysql > /tmp/mysql.sql ##备份库 [[email protected] ~]# mysql -uroot -p88888888 mysql < /tmp/mysql.sql ##恢复库 [[email protected] ~]# mysqldump -uroot -p88888888 mysql user > /tmp/user.sql ##备份表 [[email protected] ~]# mysql -uroot -p88888888 mysql < /tmp/user.sql ##恢复表 [[email protected] ~]# mysqldump -uroot -p -A >/tmp/123.sql ##备份所有库 Enter password: [[email protected] ~]# mysqldump -uroot -p88888888 -d mysql > /tmp/mysql.sql ##只备份表结构
时间: 2024-12-08 19:55:35