Home Database Mysql Tutorial MySQL数据库,不得不看(1)

MySQL数据库,不得不看(1)

Jun 07, 2016 pm 04:14 PM
mysql generally database

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>
Copy after login

增加多个字段:

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

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

增加一个管理员帐户:

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

每条语句输入完毕后要在末尾填加分号';',或者填加'\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>
Copy after login

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>
Copy after login

备份表格:(备份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>
Copy after login

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

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

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

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

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

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

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>
Copy after login

6、复制表

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

7、对表重新命名

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

8、修改列的类型

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

修改列id的类型为int unsigned

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

修改列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>
Copy after login

建立唯一性索引

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>
Copy after login

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

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

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>
Copy after login

13、MySQL不支持的功能

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

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

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

15、使用索引的缺点

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

2)占用磁盘空间;

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

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

16、分析索引效率

Statement of this Website
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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Redis: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

See all articles