search
HomeDatabaseMysql TutorialMySQL命令大全经典版

MySQL命令大全经典版

Jun 07, 2016 pm 04:14 PM
mysqlmainintroduceOrderEncyclopediaarticleclassic

以下的文章主要介绍的是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命令大全的介绍,望你能有所收获。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

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

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool