mysql的基本使用

 

手动启动服务器: 

mysqld

Mysqld --console

 

手动关闭服务器

mysqladmin –u root shutdown

 

查看环境变量

mysqladmin variables

mysqld --verbose --help

 

安装为服务

mysqld –install

 

将服务设置为手动启动模式

mysqld --install-manual

 

卸载服务

mysqld –remove

 

使用命令

NET STOP MYSQL停止服务

 

测试MySQL安装

mysqlshow

mysqlshow -u root mysql

mysqladmin version status proc

mysql test

 

登录数据库

Mysql –upoot –p123 test

 

常用语句

create database mydata;

 

use mydata;

 

create table dept

(

              deptno int primary key,

              dname varchar(14),

              loc varchar(13)

);

 

create table emp

(

              empno int primary key,

              ename varchar(10),

              job varchar(10),

              ngr int,

              hiredate datetime,

              sal double,

              conm double,

              deptno int,

              foreign key (deptno) references dept(deptno)

);

 

/*显示所有数据库*/

show databases;

 

/*显示所有表*/

show tables;

 

insert into dept values(10,'a','a');

insert into dept values(20,'b','b');

insert into dept values(30,'c','c');

insert into dept values(40,'d','d');

insert into dept values(50,'e','e');

commit;

 

select * from dept;

 

/*使用分页*/

select * from dept

order by deptno asc

limit 3,2;

 

/*插入自动递增字段*/

create table article

(

       id int primary key auto_increment,

       title varchar(255)

);

 

insert into article values(null,'aa');

 

select * from article;

 

insert into article(title) values('bb');

 

select now();

 

/*日期格式的使用*/

select date_format(now(),'%Y-%m-%d %h:%i:%s');

 

/*日期的插入*/

insert into emp values(9999,'test','clert',7369,'1981-12-23 12:23:23',8000,80,10);

 

select * from emp;

 

CREATE TABLE `department` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(255) DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`)

)

 ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

 

CREATE TABLE `employee` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(255) DEFAULT NULL,

  `departId` int(11) DEFAULT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`),

  KEY `FK4AFD4ACE92E9E01C` (`departId`),

  CONSTRAINT `FK4AFD4ACE92E9E01C` FOREIGN KEY (`departId`) REFERENCES `departmen

t` (`id`)

)

 ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 |

 

显示表结构

Desc user;

 

显示表创建语句

Show create table user;

 

退出

quit

 

引用外键

drop database hibernate;

 

create database hibernate;

 

use hibernate;

 

create table student

(

       id int primary key auto_increment,

       name varchar(20)

);

 

create table course

(

       id int primary key auto_increment,

       name varchar(20)

);

 

create table score

(

       id int primary key auto_increment,

       score float,

       studentId int references student (id),

       courseId int references course (id)

);

 

posted @ 2011-08-17 18:54  水之原  阅读(653)  评论(0编辑  收藏  举报