误删除了vps上的phpmyadmin,不得已翻阅了半天mysql指南,以下是一些mysql使用实例
连接管理
链接数据库
mysql -h localhost -u root -p
退出数据库
mysql>quit;
数据库管理
查看数据库
mysql>show databases;
建立数据库
mysql>create database name;
备份(导出)数据库
mysqldump -u username -p database > backup_db.sql
还原(导入)数据库
mysql -u username -p database < backup_db.sql
用户管理
添加用户
mysql>grant all privileges on databasename.* 'username'@'localhost' identified by 'userpassword' with grant optiton;
删除用户
mysql>drop user username;
修改密码
mysql>set password for 'username'@'localhost' = password('userpassword');
一个创建数据库并添加专用用户的示例:
mysql> create database wp;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| wp |
+--------------------+
3 rows in set (0.00 sec)
mysql> use up
ERROR 1049 (42000): Unknown database 'up'
mysql> use wp;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> grant select,insert,update,delete,create,drop
-> on wordpress.*
-> to 'wordpress'@'localhost'
-> identified by 'passwd';
Query OK, 0 rows affected (0.03 sec)