search
HomeDatabaseMysql TutorialMySQL数据库,不得不看(1)

MySQL数据库一般应用于中小企业,其不仅具有开源性,还具有很好的管理特性,我们今天就是对MySQL数据库的相关内容的介绍,我们首先是从启动:net start mySql; 开始的,以下就是文章的主要内容。 启动:net start mySql; 进入:MySQL-u root -p/MySQL-h loca

MySQL数据库一般应用于中小企业,其不仅具有开源性,还具有很好的管理特性,我们今天就是对MySQL数据库的相关内容的介绍,我们首先是从启动:net start mySql; 开始的,以下就是文章的主要内容。

启动:net start mySql;

进入:MySQL-u root -p/MySQL-h localhost -u root -p databaseName;

列出数据库:show databases;

选择数据库:use databaseName;

列出表格:show tables;

显示表格列的属性:show columns from tableName;

建立数据库:source fileName.txt;

匹配字符:可以用通配符_代表任何一个字符,%代表任何字符串;

增加一个字段:

<ol class="dp-xml"><li class="alt"><span><span>alter table tabelName add column fieldName dateType; </span></span></li></ol>

增加多个字段:

<ol class="dp-xml"><li class="alt"><span><span>alter table tabelName add column fieldName1 dateType,add columns fieldName2 dateType; </span></span></li></ol>

多行命令输入:注意不能将单词断开;当插入或更改数据时,不能将字段的字符串展开到多行里,否则硬回车将被储存到数据中;

增加一个管理员帐户:

<ol class="dp-xml"><li class="alt"><span><span>grant all on *.* to user@localhost identified by "password"; </span></span></li></ol>

每条语句输入完毕后要在末尾填加分号';',或者填加'\g'也可以;

查询时间:select now();

查询当前用户:select user();

查询数据库版本:select version();

查询当前使用的数据库:select database();

1、删除student_course数据库中的students数据表:

<ol class="dp-xml"><li class="alt"><span><span>rm -f student_course/students.*  </span></span></li></ol>

2、备份数据库:(将数据库test备份)

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -u root -p test</span><span class="tag">></span><span>c:\test.txt  </span></span></li></ol>

备份表格:(备份test数据库下的mytable表格)

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -u root -p test mytable</span><span class="tag">></span><span>c:\test.txt  </span></span></li></ol>

将备份数据导入到数据库:(导回test数据库)

<ol class="dp-xml"><li class="alt"><span><span>mysql -u root -p test  </span></span></li></ol>

3、创建临时表:(建立临时表zengchao)

<ol class="dp-xml"><li class="alt"><span><span>create temporary table zengchao(name varchar(10));  </span></span></li></ol>

4、创建表是先判断表是否存在

<ol class="dp-xml"><li class="alt"><span><span>create table if not exists students(……);  </span></span></li></ol>

5、从已经有的表中复制表的结构

<ol class="dp-xml"><li class="alt"><span><span>create table table2 select * from table1 where 1</span><span class="tag"><span class="tag">></span><span>1;  </span></span></span></li></ol>

6、复制表

<ol class="dp-xml"><li class="alt"><span><span>create table table2 select * from table1;  </span></span></li></ol>

7、对表重新命名

<ol class="dp-xml"><li class="alt"><span><span>alter table table1 rename as table2;  </span></span></li></ol>

8、修改列的类型

<ol class="dp-xml"><li class="alt"><span><span>alter table table1 modify id int unsigned; </span></span></li></ol>

修改列id的类型为int unsigned

<ol class="dp-xml"><li class="alt"><span><span>alter table table1 change id sid int unsigned; </span></span></li></ol>

修改列id的名字为sid,而且把属性修改为int unsigned

9、创建索引

<ol class="dp-xml">
<li class="alt"><span><span>alter table table1 add index ind_id (id);   </span></span></li>
<li><span>create index ind_id on table1 (id);   </span></li>
<li class="alt"><span>create unique index ind_id on table1 (id);  </span></li>
</ol>

建立唯一性索引

10、删除索引

<ol class="dp-xml">
<li class="alt"><span><span>drop index idx_id on table1;   </span></span></li>
<li><span>alter table table1 drop index ind_id;  </span></li>
</ol>

11、联合字符或者多个列(将列id与":"和列name和"="连接)

<ol class="dp-xml"><li class="alt"><span><span>select concat(id,':',name,'=') from students;  </span></span></li></ol>

12、limit(选出10到20条)

<ol class="dp-xml"><li class="alt"><span><span>select * from students order by id limit 9,10;  </span></span></li></ol>

13、MySQL不支持的功能

事务,视图,外键和引用完整性,存储过程和触发器

14、MySQL会使用索引的操作符号

=,>,=,between,in,不带%或者_开头的like

15、使用索引的缺点

1)减慢增删改数据的速度;

2)占用磁盘空间;

3)增加查询优化器的负担;

当查询优化器生成执行计划时,会考虑索引,太多的索引会给查询优化器增加工作量,导致无法选择最优的查询方案;

16、分析索引效率

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

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.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.