您的位置:首页 > 数据库 > MySQL

MySQL数据库基本操作

2013-08-30 23:49 323 查看
1,命令行登录命令

mysql -h localhost -u root -p

C:\Users\lenovo>mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


2,创建数据库

查看帮助:\h create database 或者 help create database

mysql> \h create database
Name: 'CREATE DATABASE'
Description:
Syntax:
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification] ...

create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name

CREATE DATABASE creates a database with the given name. To use this
statement, you need the CREATE privilege for the database. CREATE
SCHEMA is a synonym for CREATE DATABASE.


[option1, option2,...]代表可选的 {option1 | option2}代表要选择其中的某一项

SCHEMA是DATABASE的同义词

IF NOT EXISITS:如果不存在同名数据库才会执行创建语句;如果不添加此选项,而且存在同名数据库的话,则会报错

创建参数:

[DEFAULT] CHARACTER SET [=] charset_name:设定默认字符集

[DEFAULT] COLLATE [=] collation_name:设定默认校对集

参考在SQL语句中使用COLLATE

创建数据库示例:

mysql> create database if not exists test_db
-> default character set = utf8;


查看已创建的数据库的定义

mysql> show create database test_db;




查看已创建哪些数据库

mysql> show databases;


3,删除数据库

mysql> drop database test_db;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql