1. 程式人生 > >Windows下mysql的基礎操作

Windows下mysql的基礎操作

charset rop hang char 刪除數據 創建 databases -- cmd

1.數據庫表操作:

  • - 首先啟動mysql服務器,在安裝mysql的目錄下打開cmd窗口,運行mysql:‘mysql.exe -hlocalhost -p3306 -uroot -p123456‘;
  • - 查看所有的數據庫: show databases; -- create database my_database;
  • - use my_database; --> show tables; --> create table class(name varchar(10), room varchar(10))charset utf8; --> show tables like "%s"; -->
  •   查詢表的創建語句:show create table my_student; --> 省略冒號的寫法:show create table my_student\g --> 另外一種輸出格式:
  •   show create table my_student\G
  • - 給表重命名:rename table student to my_student;
  • - 查看數據表的表結構:desc 表名; -->describe 表名; --> show columns from 表名;
  • - 給表添加新的字段:alter table my_student add column id int first/after;
  • - 修改字段:修改通常是屬性或者數據類型;--> alter table 表名 mondify 字段名 數據類型 [屬性] [位置]; --> alter table my_student modify number char(10) after id;
  • - 重命名字段:alter table 表名 change 舊字段 新字段 數據類型 [屬性] [位置];
  •   alter table my_student change gender sex varchar(10) after id;
  • - 刪除字段:刪除學生表中的年齡字段(age) --> alter table my_student drop age;
  • - 刪除數據表:drop table 1,2,3... --> drop table class;

Windows下mysql的基礎操作