搜索
首页数据库mysql教程MySQL命令大全经典版

MySQL命令大全经典版

Jun 07, 2016 pm 04:14 PM
mysql主要介绍命令大全文章经典

以下的文章主要介绍的是MySQL命令大全,其中包括MySQL数据库的常用命令,修改MySQL数据库中实际root 密码以及对grant的实际应用的介绍,下面就是文章的具体内容描述,望你会有所收获。 MySQL命令大全1、MySQL常用命令 create database name; 创建数据库 use

以下的文章主要介绍的是MySQL命令大全,其中包括MySQL数据库的常用命令,修改MySQL数据库中实际root 密码以及对grant的实际应用的介绍,下面就是文章的具体内容描述,望你会有所收获。

MySQL命令大全1、MySQL常用命令

create database name; 创建数据库

use databasename; 选择数据库

drop database name 直接删除数据库,不提醒

show tables; 显示表

describe tablename; 表的详细描述

select 中加上distinct去除重复字段

MySQLadmin drop databasename 删除数据库前,有提示。

显示当前MySQL版本和当前日期

<ol class="dp-xml"><li class="alt"><span><span>select version(),current_date;  </span></span></li></ol>

MySQL命令大全2、修改MySQL中root的密码:

<ol class="dp-xml">
<li class="alt">
<span><span>shell</span><span class="tag">></span></span>MySQL<span><span> -u root -p   </span></span>
</li>
<li>MySQL<span class="tag">></span><span> update user set </span><span class="attribute">password</span><span class="attribute-value">password</span><span>=password(”xueok654123″) where </span><span class="attribute">user</span><span>=’root’;   </span>
</li>
</ol>

MySQL> flush privileges //刷新数据库

MySQL>use dbname; 打开数据库:

MySQL>show databases; 显示所有数据库

MySQL>show tables; 显示数据库MySQL中所有的表:先use MySQL;然后

MySQL>describe user; 显示表MySQL数据库中user表的列信息);

3、grant

创建一个可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令something做这个

MySQL> grant all privileges on *.* to user@localhost identified by ’something’ with

增加新用户

格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”

<ol class="dp-xml">
<li class="alt"><span><span>GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY ’something’ WITH GRANT OPTION;   </span></span></li>
<li><span>GRANT ALL PRIVILEGES ON *.* TO monty@”%” IDENTIFIED BY ’something’ WITH GRANT OPTION;   </span></li>
</ol>

删除授权:

<ol class="dp-xml">
<li class="alt">MySQL<span><span class="tag">></span><span> revoke all privileges on *.* from root@”%”;   </span></span>
</li>
<li>MySQL<span class="tag">></span><span> delete from user where </span><span class="attribute">user</span><span>=”root” and </span><span class="attribute">host</span><span>=”%”;   </span>
</li>
<li class="alt">MySQL<span class="tag">></span><span> flush privileges;   </span>
</li>
</ol>

创建一个用户custom在特定客户端it363.com登录,可访问特定数据库fangchandb

<ol class="dp-xml"><li class="alt">MySQL<span> </span><span>>grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by ‘ passwd’  </span>
</li></ol>

重命名表:

<ol class="dp-xml"><li class="alt">MySQL<span> </span><span>> alter table t1 rename t2;  </span>
</li></ol>

MySQL命令大全4、MySQLdump

备份数据库

<ol class="dp-xml"><li class="alt">shell> MySQL<span>dump -h host -u root -p dbname </span><span>>dbname_backup.sql  </span>
</li></ol>

恢复数据库

<ol class="dp-xml">
<li class="alt">shell> MySQLadmin -h myhost -u root -p create dbname   </li>
<li>
<span>shell</span><span class="tag">></span><span> </span>MySQL<span>dump -h host -u root -p dbname </span><span class="tag"><span> </span><span class="tag-name">dbname_backup.sql</span><span>   </span></span>
</li>
</ol>

如果只想卸出建表指令,则命令如下:

<ol class="dp-xml"><li class="alt">shell> MySQL<span>admin -u root -p -d databasename </span><span>> a.sql  </span>
</li></ol>

如果只想卸出插入数据的sql命令,而不需要建表命令,则命令如下:

<ol class="dp-xml"><li class="alt">shell> MySQL<span>admin -u root -p -t databasename </span><span>> a.sql  </span>
</li></ol>

那么如果我只想要数据,而不想要什么sql命令时,应该如何操作呢?

<ol class="dp-xml"><li class="alt">MySQL<span>dump -T./ phptest driver  </span>
</li></ol>

其中,只有指定了-T参数才可以卸出纯文本文件,表示卸出数据的目录,./表示当前目录,即与MySQLdump同一目录。如果不指定driver 表,则将卸出整个数据库的数据。每个表会生成两个文件,一个为.sql文件,包含建表执行。另一个为.txt文件,只包含数据,且没有sql指令。

5、可将查询存储在一个文件中并告诉MySQL从文件中读取查询而不是等待键盘输入。可利用外壳程序键入重定向实用程序来完成这项工作。例如,如果在文件my_file.sql 中存放有查

询,可如下执行这些查询:

例如,如果您想将建表语句提前写在sql.txt中:

<ol class="dp-xml"><li class="alt">MySQL<span> </span><span class="tag">></span><span> </span>MySQL<span> -h myhost -u root -p database </span><span class="tag"><span> </span><span>sql.txt  </span></span>
</li></ol>

以上的相关内容就是对MySQL命令大全的介绍,望你能有所收获。


声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
在MySQL中使用视图的局限性是什么?在MySQL中使用视图的局限性是什么?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

确保您的MySQL数据库:添加用户并授予特权确保您的MySQL数据库:添加用户并授予特权May 14, 2025 am 12:09 AM

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素会影响我可以在MySQL中使用的触发器数量?哪些因素会影响我可以在MySQL中使用的触发器数量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存储斑点安全吗?mysql:存储斑点安全吗?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通过PHP Web界面添加用户mySQL:通过PHP Web界面添加用户May 14, 2025 am 12:04 AM

通过PHP网页界面添加MySQL用户可以使用MySQLi扩展。步骤如下:1.连接MySQL数据库,使用MySQLi扩展。2.创建用户,使用CREATEUSER语句,并使用PASSWORD()函数加密密码。3.防止SQL注入,使用mysqli_real_escape_string()函数处理用户输入。4.为新用户分配权限,使用GRANT语句。

mysql:blob和其他无-SQL存储,有什么区别?mysql:blob和其他无-SQL存储,有什么区别?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

mySQL添加用户:语法,选项和安全性最佳实践mySQL添加用户:语法,选项和安全性最佳实践May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串数据类型常见错误?MySQL:如何避免字符串数据类型常见错误?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具