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
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment