Linux操作系统操作MySQL常用命令小结
下面给大家分享mysql常用命令,
--启动数据库
servicemyslqdstart;
--进入MySQL-uroot-p/mysql-hlocalhost-uroot-pDatabaseName;
--列出数据库
showdatabase;
--创建数据库
createdatabaseXXXX;
--选择数据库
useDatabaseName;
--罗列表
showtable;
--显示表格的属性
showcolumnsfromtablename;
--建立数据库
sourcefilename.txt;
--增加一个字段
altertabletablenameaddcolumnfilenamedatatype;
--增加多个字段
altertabletablenameaddcolumnfilename1datatype,addcolumnfilename2datatype;
--新增一个用户
grantallOn*.*touser@localhostidentityby"password";
--查询时间
selectnow();
--查询用户
selectuser();
--查询数据库版本
selectversion();
--查询当前使用的数据库
selectdatabase();
--删除student_course数据库中的student数据便
rm-fstudent_cource/student.*
--备份数据库(备份数据库Apple1)
MySQLdump-uroot-pApple1>C:\Apple1.txt
--备份表(将数据库Apple1中的mytable表备份)
MySQLdump-uroot-pmytable>C:\Apple.txt
--创建临时表(mytable)
createtemporarytablemytable(idint,addressvarchar(20),namevarchar(20));
--创建表前先判断系统是否存在这个表
createtableifnotexistsmytable(......);
--从已有的table1表中复制表结构到table2
createtabletable2select*fromtable1where1<>1;
--复制表
createtabletable2select*fromtable1;
--重命名表名
altertabletable1renameastable2;
--修改列的数据类型
altertabletable1modifyIDintunsigned;--把列ID的类型修改为intunsigned
altertabletable1changeIDSIDintunsigned;--把列ID改名为SID且类型改为intunsigned
--创建索引
altertabletable1addindexInd_id(ID);
createindexind_IDontablename(ID);
createuniqueindexind_idontablename(ID);
--删除索引
dropindexind_idOntable1;
altertabletable1dropindexind_ID;
--联合查询字符与多个列连接‘
selectconcat(ID,':',name,'=')fromtable1
-----------------------第二片------------------------------------
--显示数据库
showdatabase;
--显示数据库中的表
showtables;
--显示数据表结构
describetablename;
--显示表记录
select*fromtablename;
--查询能操作MySQL的用户
select*fromuser;
--创建数据库
createdatabasedatabasename
--例如↓
MySQL>createdatabaseAA;
---创建表
userAA;
mysql>createtabletable1(IDintauto_incrementnotnullprimarykey,namechar(6),sexchar(6),birthdaydate)
---插入几条记录
MySQL>insertintoAAvalues('','张三','男','1971-10-01');
MySQL>insertintoAAvalues('','刘佳佳','女','1978-10-01');
--验证结果
MySQL>select*fromAA;
--修改张三的生日为1971-01-10
MySQL>updateAAsetbirthday='1971-01-10'whereID='1';
--删除记录
MySQL>deletefromAAwhereID='1';
--删除表以及库
mysql>droptabletablename;
MySQL>dropdatabasedatabasename;
--新增万能用户
--格式:grantselectOndatabase.*tousername@localhostidentityby'password'
用户名user_1密码是123456
--可以自任何PC上登录这个用户对数据库为所欲为
MySQL>grantselect,insertupdate,deleteon*.*touser_1@"%"identityby"123456";
--创建只有在本机才能操作数据库的用户
用户名user_2密码是123456
MySQL>grantselect,insertupdate,deleteon*.*touser_2@localhostidentityby"123456";
--登录数据库库
MySQL>-uuser_1-p-hIP地址;
以上所述是小编给大家介绍的Linux操作系统操作MySQL常用命令小结,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!