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

MySQL学习笔记

2010-11-19 22:15 176 查看
今天开始学习MySQL,主要学习资料来源于MySQL的官方网站:http://dev.mysql.com/doc/refman/5.1/zh/index.html

一、启动MySQL

在安装完MySQL以后,可以将安装路径添加到系统路径中,通常,我都是在安装的时候选择相应的复选框的。

在CMD中输入mysql -u root -p<ENTER>,再输入密码即可启动MySQL。

C:/Users/Michael>mysql -u root -p

Enter password: ********

Welcome to the MySQL monitor. Commands end with ; or /g.

Your MySQL connection id is 4

Server version: 5.1.52-community MySQL Community Server (GPL)

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

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql>

如果想方便,也可以这么输入:mysql -uroot -p******,后面的******为root的密码。

在Linux环境下,有时会在shell脚本中使用到mysql命令,此时,通常希望执行完这行命令后能够自动退出,那么可以在启动MySQL时,添加一个参数-e

二、退出MySQL

在mysql命令环境下输入quit;<ENTER>即可退出。

mysql> quit;

三、数据库的相关操作

(1)显示当前数据库信息

mysql> show databases;



(2)设置当前使用数据库





mysql> use test;

Database changed

(3)查看当前数据库中所有表的信息

mysql> show tables;



(4)查看表的详细信息

mysql> describe files;

(5)创建表

mysql> create table user(

-> id int not null key,

-> name varchar (10) not null,

-> mail varchar(50) not null

-> );

Query OK, 0 rows affected (0.24 sec)

关于创建表的语法还有很多详细信息,请参见:http://dev.mysql.com/doc/refman/5.1/zh/sql-syntax.html#create-table

创建好相应的表,可以使用describe table_name;来查看相应信息。



(6)其他的数据库相关操作就不多说了,如果有兴趣,可以参考mysql的参考手册,上面写的很详细。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: