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

MySQL使用实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:33:29
Original
1100 people have browsed it

误删除了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)
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template