成都十班-李文倩 发表于 2021-11-22 21:25:57

MySQL数据库

【MySQL数据库】1. # yum install mysql安装MySQL数据库客户端2. # yum install mysql-server安装MySQL数据库服务端3. # service mysqld start启动MySQL数据库4. service mysqld stop停止MySQL数据库5. service mysqld status查看MySQL数据库的状态6. service mysqld restart重启MySQL数据库 注意:每次访问数据库,都要保证数据库是启动状态。7. mysql -uroot -p 进入MySQL数据库,-uroot表示使用root用户,-p表示密码8. mysqladmin -uroot password ‘123456’ 给root用户设置访问密码9. mysql -uroot -p123456直接带密码的方式访问MySQL数据库10. mysql>   show databases; 查看MySQL数据库里面所有的数据库11. create database dcs10;创建一个名字为dcs10的数据库空库12. use dcs10; 使用use+库名进入到某个数据库里13. show tables; 查看进入数据库里所有的表14. create table test(id int(20) primary key auto_increment,name varchar(20) not null,score float(20,2),phone bigint(20) default 15366669999,time date);创建一个名字为test的表15. desc+表名;   查看表结构/查看表定义16. drop database dcs11;   删除dcs11这个空库17. alter table test rename test1;将test表名改为test118. alter table test change id sid int(20); 将id字段改为sit,并且去掉自增长19. alter table test change sid sid int(20) auto_increment; 将sit字段增加自增长约束20. alter table test add class int(20) first; 将test表添加一个class字段放在最前面21. alter table test add sex varchar(20) after class; 添加一个字段sex放在class后面22. alter table test drop sex;删除sex字段23. alter table test add(sex varchar(20),age int(20));同时添加两个字段sex和age默认放在表字段最后面24. alter table test drop sex,drop age;同时删除两个字段25. alter table test modify name varchar(20) after class; 将name字段放在class字段后面26. create table test1(id int(20),name varchar(20));   新建一个test1表27. drop table test1;删除test1表28. alter table test drop primary key; 删除自增长之后,再去删除主键约束就可以成功29. alter table test change sid sid int(20) primary key auto_increment; 最后再给sit字段添加主键约束和自增长约束 30. insert into test(sid,name,class,score,phone,time)values(1,’xiaoyi’,2021,66.666,17633335555,’2021-11-21’);    将test表所有的字段都插入数据31. select * from test;查询test表所有的数据,*表示所有字段32. alter table test change name name varchar(20) not null; 给name字段增加不能为空的属性
页: [1]
查看完整版本: MySQL数据库