mysql查看数据库命令

时间:2022-03-23 04:41:34

mysql查看数据库命令

  打开的数据库的命令

  mysql> use mysql

  Database changed

  查看数据库的命令

  mysql> show databases;

  查看数据表的详细结构

  mysql> desc func;

  新建数据库

  mysql> create database school;

  Query OK, 1 row affected (0.00 sec)

  新建表

  mysql> create table user01(

  -> id varchar(20) NOT NULL,

  -> userName varchar(10) NOT NULL,

  -> age int(11) default'0',

  -> sex char(2) NOT NULL default'm',

  -> PRIMARY KEY (id)

  -> )TYPE=InnoDB;

  Query OK, 0 rows affected, 1 warning (0.02
sec)mysql>desc student;

  插入和删除表中的数据

  Create table student(stuName varchar(20),age varchar(20),id
varchar(20),set0 char(1));

  插入

  mysql> insert into student(id,stuName)
values('1','tomcat');

  Query OK, 1 row affected (0.00 sec)

  删除

  mysql> delete from student where id='1';

  Query OK, 1 row affected (0.01 sec)

  删除表中所有数据

  mysql> truncate table student;

  Query OK, 1 row affected (0.01 sec)

  删除表

  mysql> create table temp(t varchar(1));

  Query OK, 0 rows affected (0.00 sec)

  mysql> drop table temp;

  Query OK, 0 rows affected (0.00 sec)

  创建新用户并给予权限

  mysql> grant all privileges on *.* to
dbuser@localhost identified by '1234'

  with grant option;

  更改Mysql用户密码

  c:\Mysql5.0\bin>mysqladmin -u root -p password
1234

  Enter password: ****

  备份数据库及表

  我们用mysqldump命令来备份数据库

  c:\mysql\bin\>mysqldump –u root –p 3306
mysql>d:\backup.sql

  执行此语句将把mydb 备份到D盘的backup.sql文件中

  备份多个数据库表

  c:\mysql\bin\>mysqldump –u root –p 3306 school
user01 user >d:\backup.sql

  此句的意思是把school库中的user01表和user表的内容和表的定义备份到D盘backup.sql文件中。

  备份所有的数据库

  c:\myql\bin>mysqldump –u root –p 3306 –all
–database>d:backup.sql

  还原Mysql数据库

  c:\mysql\bin\mysql –u root –p 3306 school

  还原其中的一个表

  mysql> source d:\books.sql;

  ERROR:

  Unknown command '\b'.

  Query OK, 0 rows affected (0.00 sec)

  Query OK, 1 row affected (0.00 sec)

  退出Mysql连接

  mysql>quit(exit)

  关闭mysql服务

  C:\mysql\bin>net mysql