Home Database Mysql Tutorial MySql基础总结(1)_MySQL

MySql基础总结(1)_MySQL

Jun 01, 2016 pm 01:01 PM
Base

对于MySql已经是第二次看了,这次主要的目的是将MySql系统的归纳一边,之前学MySql是将笔记写在本子上,以后不想总带着本子,所以再花点时间把笔记归纳在博客中。下午已将安装步骤详细的写了,现在归纳他的基本语法。至于语法很多都是满足Sql语法的,和Sql Server 、Oracle都差不多。符合“>”后的都是在dos中验证过的,并且复制后直接可以运行。

1.连接数据库:

>#在mysql中‘#’是注释符号,连接数据库时,输入账号和密码

>mysql -u root -p wwh

2.显示所有的数据库

>show databases;

3.切换,显示某个数据库

>use test;

4.显示对应数据库中的所有表:
>show tables;

5.创建一个名称为user的数据库
>create database user;
6.创建一个使用utf8字符集的user数据库
>create database if not exists user character set UTF8;
>#如果不存在user,就创建,如果存在,则不创建user数据库
7.创建一个使用utf8字符集,并带校对规则的user数据库
>create database if not exists user character set UTF8 collate utf8_general_ci;

8.查看前面创建的user数据库的定义信息
>show create database user;

9.删除前面创建的user数据库
>drop database if exists user;

10.查看服务器中的数据库,并把其中user库的字符集修改为gbk
>alter database user character set gbk;

11.修改、备份、恢复数据库数据(这应该算是MySql中特有的吧,不同的数据库备份恢复的指令不一样)
备份:
c:\> mysqldump -u root -p wwh > d:\user.sql 回车(可以无分号结束)
密码回车
注意:该SQL命令是MySQL特有的,必须是MySQL环境外执行,即Window中dos界面环境中执行,并未进入到MySql的服务器中。
恢复:
mysql:\> source d:\mydb2.sql;回车(需要分号结束)
注意:该SQL命令是MySQL特有的,必须是MySQL环境中执行。

12. MySQL支持数据类型


\

注意:

 

(1)Date/Datetime/TimeStamp,定界符使用''或""(单引号和双引号),但部份数据库可能不支持"",优先推荐''作为定界符,对于日期类型, MySQL数据库有一个的判段-功能
(2)varchar(变长)/char(定长)
(3)Text(大于65536字符的数据)/Blob(存储二进制多媒体数据,例如Mp3等),该二类型都有四个子类型,根据存储内容的大小进行选择
(4)INT型有带符号和无符号之分,int(5)表示int默认为5位,如果插入id值,小于5位,左补空格,如果插入id值,大于5位,按照插入值,但必须满足int类型的大小确定

(5)FLOAT(M,D),D表示小数点后的D位,按四舍五入计算,M表示除小数点外的所有位数总和

(6)tinyint/smallint/mediumint/int/bigint-->1B/2B/3B/4B/8B

13.优化的方法:

以时间换空间或者以空间换时间。

14.注意:

在实际的开发中,可以考虑吧频繁用到的信息,优先考虑效率,存储到一张表中,把不常用的信息和比较占空间的信息,有限考虑空间占用,存储到辅表中。例如:QQ空间中的用户名和密码,还有日志和留言板的信息存储。

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 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)

PHP Basics Tutorial: From Beginner to Master PHP Basics Tutorial: From Beginner to Master Jun 18, 2023 am 09:43 AM

PHP is a widely used open source server-side scripting language that can handle all tasks in web development. PHP is widely used in web development, especially for its excellent performance in dynamic data processing, so it is loved and used by many developers. In this article, we will explain the basics of PHP step by step to help beginners from getting started to becoming proficient. 1. Basic syntax PHP is an interpreted language whose code is similar to HTML, CSS and JavaScript. Every PHP statement ends with a semicolon; Note

Can I learn Linux from scratch? What do I need to learn? Can I learn Linux from scratch? What do I need to learn? Feb 19, 2024 pm 12:57 PM

If you want to work in the IT industry, but do you want to learn programming, which technology should you choose? Of course it is Linux operation and maintenance. Linux is a very popular technology on the market, with a wide range of applications and good employment prospects, and is liked by many people. So the question is, can I learn Linux operation and maintenance with zero basic knowledge? In the server market, Linux system has a market share of up to 80% because of its advantages such as stability, security, free open source, efficiency and convenience. From this, it can be seen that Linux applications are very popular. Extensive. Whether now or in the future, learning Linux is a very good choice. As for whether it is possible to learn from scratch? My answer is of course. Oldboy Education Linux face-to-face class is specially designed for people with zero basic knowledge

Introduction to PHP Basics: How to use the echo function to output text content Introduction to PHP Basics: How to use the echo function to output text content Jul 30, 2023 pm 05:38 PM

Basic introduction to PHP: How to use the echo function to output text content. In PHP programming, you often need to output some text content to a web page. In this case, you can use the echo function. This article will introduce how to use the echo function to output text content and provide some sample code. Before starting, first make sure you have installed PHP and configured the running environment. If PHP is not installed yet, you can download the latest stable version from the PHP official website (https://www.php.net).

Learn the basics of Go language variables Learn the basics of Go language variables Mar 22, 2024 pm 09:39 PM

Go language is a statically typed, compiled language developed by Google. Its concise and efficient features have attracted widespread attention and love from developers. In the process of learning the Go language, mastering the basic knowledge of variables is a crucial step. This article will explain basic knowledge such as the definition, assignment, and type inference of variables in the Go language through specific code examples to help readers better understand and master these knowledge points. In the Go language, you can use the keyword var to define a variable, which is the format of the var variable name variable type.

Detailed explanation of C language functions: basic to advanced, comprehensive analysis of the use of functions Detailed explanation of C language functions: basic to advanced, comprehensive analysis of the use of functions Feb 18, 2024 pm 02:25 PM

C language function encyclopedia: from basic to advanced, detailed explanation of how to use functions, specific code examples are required Introduction: C language is a widely used programming language, and its powerful functions and flexibility make it the first choice of many developers. In C language, function is an important concept. It can combine a piece of code into an independent module, improving the reusability and maintainability of the code. This article will introduce the use of C language functions from the basics and gradually advance to help readers master the skills of function writing. 1. Definition and calling of functions in C

PHP study notes: Basics of object-oriented programming PHP study notes: Basics of object-oriented programming Oct 09, 2023 pm 12:46 PM

PHP study notes: Basics of object-oriented programming, specific code examples are required Introduction: Object-Oriented Programming (OOP for short) is a programming way of thinking that decomposes the problem into multiple objects and defines the interaction between objects. to solve complex programming problems. As a powerful programming language, PHP also supports object-oriented programming. This article will introduce the basic concepts and common syntax of object-oriented programming in PHP, and provide specific code examples. kind

PHP study notes: basic syntax and variable definition PHP study notes: basic syntax and variable definition Oct 09, 2023 am 08:03 AM

PHP study notes: basic syntax and variable definition In today's Internet era, PHP (Hypertext Preprocessor), as a widely used server scripting language, is favored by more and more developers. This article will introduce you to the basic syntax of PHP and the definition of variables, and provide specific code examples to help beginners better understand and master it. 1. Basic syntax of PHP Markings of PHP code In PHP code, we often use "<?php" and "?&

PHP function usage: from basics to advanced PHP function usage: from basics to advanced Jun 15, 2023 pm 11:11 PM

PHP is a widely used server-side scripting language used to develop dynamic websites, web applications, and other Internet services. In the process of developing PHP applications, using functions can help simplify code, improve code reusability, and reduce development costs. This article will introduce the basic usage and advanced usage of PHP functions. 1. Basic usage of PHP functions 1. Define functions In PHP, use the function keyword to define functions, for example: functiongreet($name){

See all articles