1. 添加,受权用户
mysql> mysql> -> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass'; //建立用户GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'WITH GRANT OPTION; //受权用户
mysql> SHOW GRANTS FOR 'admin'@'localhost'; //查看用户权限 granted
mysql> SHOW CREATE USER 'admin'@'localhost'\G //查看用户权限 ungranted
mysql> mysql> -> -> CREATE USER 'custom'@'localhost' IDENTIFIED BY 'obscure';GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROPON bankaccount.*TO 'custom'@'localhost'; //部分受权
mysql> mysql> -> -> mysql> mysql> -> -> CREATE USER 'custom'@'host47.example.com' IDENTIFIED BY 'obscure';GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROPON expenses.*TO 'custom'@'host47.example.com';CREATE USER 'custom'@'%.example.com' IDENTIFIED BY 'obscure';GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROPON customer.*TO 'custom'@'%.example.com';
The first account can access the bankaccount
database, but only from the local host.mysql
The second account can access the expenses
database, but only from the host host47.example.com
.sql
The third account can access the customer
database, from any host in the example.com
domain. This account has access from all machines in the domain due to use of the “%
” wildcard character in the host part of the account name.数据库
2. 修改密码
root@localhost[(none)]> set password for 'fred'@'localhost'=password('passwd'); app
Query OK, 0 rows affected (0.00 sec) dom
3. 使用mysqldump导出固定条件的数据库,使用source导入数据库编码
咱们来看几个经常使用用例:
(1)导出整个数据库spa
mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
(2)导出一个表code
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
(3)导出一个数据库结构blog
mysqldump -u wcnc -p -d --add-drop-table smgp_apps_wcnc >d:\wcnc_db.sql #-d 不导出数据只导出结构 --add-drop-table 在每一个create语句以前增长一个drop table
(4)导入数据库,经常使用source 命令input
#进入mysql数据库控制台, mysql -u root -p mysql>use 数据库
mysql>set names utf8; (先确认编码,若是不设置可能会出现乱码,注意不是UTF-8) #而后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql>source d:\wcnc_db.sql
4. 删除数据库drop database 数据库名