mysql 日常使用

啓動
windows 1 net start mysql 2 X:\installpath\bin\mysqld -u root (Enter)
linux 1 service mysqld start 2 service mysql start 3 /etc/inint.d/mysqld start
停止
windows 1 net stop mysql 2 mysqladmin -u root [-p password]
linux 1 service mysqld stop 2 /etc/inint.d/mysqld stop 3 mysqladmin shutdown
重啓
linux 1 service mysqld restart 2 service mysql restart 3 /etc/init.d/mysqld restart
登錄
mysql -h host -u user -p 回車 password
創建用戶
1 create user 'username'@'host' [IDENTIFIED BY 'password'](不寫爲空密碼);
  host 1localhost本地(默認) 2指定主機(ip) 3任意地方(%)
2 insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
刪除用戶

1 drop user user@host
2 Delete FROM user Where User='test' and Host='host';
用戶授權
grant 授權
all privileges 所有權限,可以單獨給[select,delete,update,create,drop]
on DB(指定DB或者*所有DB).*(表) 
to root@localhost 用戶@訪問主機
identified by 'pass' 密碼
刷新權限
flush privileges 刷新系統權限表

優化
1 字段類型爲varchar有索引, sql中使用int查詢用不到索引,反之字段屬性爲int有索引,sql查詢用"字符串"可以用到索引
2 where條件中用到了聯合索引,但聯合索引裏沒有排序字段,order by索引用不到(嚴重影響速度),如果排序字段爲多個不是同方向排序也可能用不上索引
3 like 時左邊%時索引失效

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章