差異處
這裏顯示兩個版本的差異處。
下次修改 | 前次修改 | ||
mysql [2016/08/17 13:17] jz 建立 |
mysql [2019/02/19 02:06] (目前版本) jz [Change credential] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | ===== Auto complete CLI ===== | + | ===== Install mycli ===== |
- | + | ||
- | Install mycli | + | |
[[https://github.com/dbcli/mycli|mycli]] | [[https://github.com/dbcli/mycli|mycli]] | ||
+ | |||
<code bash> | <code bash> | ||
yaourt -S mycli | yaourt -S mycli | ||
</code> | </code> | ||
- | Login to mysql shell | + | ===== Login to mysql shell ===== |
<code bash> | <code bash> | ||
mycli -u root -p | mycli -u root -p | ||
行 14: | 行 13: | ||
===== Create database ===== | ===== Create database ===== | ||
<code sql> | <code sql> | ||
- | CREATE DATABASE menagerie; | + | CREATE DATABASE newdatabase; |
- | USE menagerie | + | USE newdatabase |
</code> | </code> | ||
- | shell> mysql -h host -u user -p menagerie | + | ===== Create user and grant the database access ===== |
- | + | <code sql> | |
- | + | CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'newpassword'; | |
- | Change root crendential | + | GRANT ALL PRIVILEGES ON newdatabase.* TO 'newuser'@'localhost'; |
+ | </code> | ||
+ | ===== Change credential ===== | ||
+ | <code bash> | ||
mysqladmin -u root password 'new-password' | mysqladmin -u root password 'new-password' | ||
mysqladmin -u root -h localhost password 'new-password' | mysqladmin -u root -h localhost password 'new-password' | ||
+ | </code> | ||
- | --- | + | <code mysql> |
+ | SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password'); | ||
+ | -- or | ||
+ | update mysql.user set password=PASSWORD(‘新password’) where User=’root’; | ||
+ | -- and then | ||
+ | flush privileges; | ||
+ | </code> | ||
- | mysql> SHOW DATABASES; | + | ===== Show users ===== |
+ | <code sql> | ||
+ | select * from mysql.user; | ||
+ | </code> | ||
- | mysql> select host, user, password from mysql.user; | + | ===== Show grants ===== |
- | mysql> SHOW GRANTS FOR username@localhost; | + | <code sql> |
+ | SHOW DATABASES; | ||
+ | SELECT host, user, password FROM mysql.user; | ||
+ | SHOW GRANTS FOR username@localhost; | ||
+ | </code> | ||
+ | |||
+ | ===== Remote grants ===== | ||
+ | <code sql> | ||
+ | revoke all privileges on newdatabase.* from 'newuser'@'localhost'; | ||
+ | flush privileges; | ||
+ | </code> | ||
+ | |||
+ | ===== List databases ===== | ||
+ | <code sql> | ||
+ | SHOW DATABASES | ||
+ | </code> | ||
+ | |||
+ | ===== List tables ===== | ||
+ | <code sql> | ||
+ | SHOW TABLES | ||
+ | </code> | ||