1. 程式人生 > >MySQL常用操作(下)

MySQL常用操作(下)

mysql

用戶管理

mysql> grant all on *.* to [email protected] identified by ‘123456‘; ##創建用戶並授權

mysql> grant SELECT,UPDATE,INSERT on db1.* to [email protected] identified by ‘passwd‘;

mysql> grant all on db1.* to [email protected]%‘ identified by ‘passwd‘;

mysql> show grants;                           ##查看授權

mysql> show grants for [email protected]
/* */; mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected] 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 ##只備份表結構


本文出自 “Gorilla City” 博客,請務必保留此出處http://juispan.blog.51cto.com/943137/1958501

MySQL常用操作(下)