Home >Database >Mysql Tutorial >MySQL使用实例

MySQL使用实例

WBOY
WBOYOriginal
2016-06-07 16:33:291095browse

误删除了vps上的phpmyadmin,不得已翻阅了半天mysql指南,以下是一些mysql使用实例 连接管理 链接数据库 mysql -h localhost -u root -p 退出数据库 mysql>quit; 数据库管理 查看数据库 mysql>show databases; 建立数据库 mysql>create database name; 备份(

误删除了vps上的phpmyadmin,不得已翻阅了半天mysql指南,以下是一些mysql使用实例

连接管理

  1. 链接数据库

    mysql -h localhost -u root -p

  2. 退出数据库

    mysql>quit;


数据库管理

  1. 查看数据库

    mysql>show databases;

  2. 建立数据库

    mysql>create database name;

  3. 备份(导出)数据库

    mysqldump -u username -p database > backup_db.sql

  4. 还原(导入)数据库

    mysql -u username -p database


用户管理

  1. 添加用户

    mysql>grant all privileges on databasename.* 'username'@'localhost' ->identified by 'userpassword' with grant optiton;

  2. 删除用户

    mysql>drop user username;

  3. 修改密码

    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)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn