標籤:query select 不用 分享圖片 sql 0 rows vpd 表示 結構
mysql使用者管理
建立一個網站需要串連Mysql,預設是root使用者,但是我們不能總是串連root,萬一操作錯誤就會出問題
對於某個資料庫,給user1設定許可權grant all on *.* to ‘user1‘ identified by ‘passwd‘;
mysql> grant all on *.* to ‘user‘ identified by ‘123‘;Query OK, 0 rows affected (0.00 sec)
grant all on *.* to ‘user1‘ @‘127.0.0.1‘ identified by ‘123456a‘;
grant:授權all:所有的許可權*.*:表示所有,第一個*表示庫名@後面也可寫成%,表示通配,所有的ip使用的是socket通訊
此時,我們退出mysql資料庫後再串連mysql,出現報錯,因為預設串連使用的是socket,當授權是localhost時,可以直接連接mysql
我們也可以不用給所有的許可權,只給定幾個許可權grant SELECT,UPDATE,INSERT on db1.* to ‘user2‘@‘192.168.37.1‘ identified by ‘passwd‘;
grant all on db1.* to ‘user3‘@‘%‘ identified by ‘passwd‘;
show grants; //查看所有的授權,目前使用者的授權
show grants for [email protected]; //查看指定使用者的授權
常用的sql語句
select count(*) from mysql.user; //count(*)表示尋找表的行數
select count(*) from mysql.user; //count(*)表示尋找表的行數
select * from mysql.db;
select db from mysql.db; //db表示欄位
select db,user from mysql.db;
select * from mysql.db where host like ‘192.168.%‘; //模糊比對
insert into db1.t1 values (1, ‘abc‘); //name欄位abc是字串,最好加上單引號
update db1.t1 set name=‘aaa‘ where id=1;
delete from db1.t1 where id=2; //刪除操作
truncate table db1.t1; //只是清空資料
drop table db1.t1; //所有的資料、結構等全清空
drop database db1; //刪掉資料庫db1
mysqlDatabase Backup
備份庫 mysqldump -uroot -p123456 mysql > /tmp/mysql.sql
恢複庫 mysql -uroot -p123456 mysql < /tmp/mysql.sql
備份表 mysqldump -uroot -p123456 mysql user > /tmp/user.sql //庫與表之間用空格分開
恢複表 mysql -uroot -p123456 mysql < /tmp/user.sql //恢複表只需要寫上庫名
備份所有庫 mysqldump -uroot -p123456 -A >/tmp/123.sql //-A表示所有的庫
只備份表結構 mysqldump -uroot -p123456 -d mysql > /tmp/mysql.sql
mysql使用者管理、常用sql語句、mysqlDatabase Backup