search
HomeDatabaseMysql TutorialMySQL 5.1学习笔记(1)-基本操作_MySQL

参考了官方文档: http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html

命令行登录数据库(mysql -uroot -p直接跟密码, 不带空格, 可以直接登录)

1 shell> mysql -ptest<br>2 shell> mysql -p test<br>3 第一个命令让mysql使用密码test,但没有指定默认数据库。第二个命令让mysql提示输入 密码并使用test作为默认数据库。

mysql -u root -p
输入密码

查看数据库列表
show databases

+--------------------+<br>| Database           |<br>+--------------------+<br>| information_schema |<br>| cdcol              |<br>| menagerie          |<br>| mysql              |<br>| phpmyadmin         |<br>| roadofhonda        |<br>| spring             |<br>| test               |<br>+--------------------+<br>8 rows in set (0.00 sec)


创建数据库
CREATE DATABASE menagerie;

切换到数据库menagerie
use menagerie

创建数据表
CREATE TABLE pet (<br>    name VARCHAR(20),<br>    owner VARCHAR(20),<br>    species VARCHAR(20),<br>    sex CHAR(1),<br>    birth DATE,<br>    death DATE<br>);


到mysql安装目录的data下去查看, 多了一个文件夹menagerie, 进入文件夹, 发现有这样几个文件

pet.frm 结构文件<br>pet.MYD 数据文件<br>pet.MYI 索引文件

查看创建表的信息
DESCRIBE pet

+---------+-------------+------+-----+---------+-------+<br>| Field   | Type        | Null | Key | Default | Extra |<br>+---------+-------------+------+-----+---------+-------+<br>| name    | varchar(20) | YES  |     | NULL    |       |<br>| owner   | varchar(20) | YES  |     | NULL    |       |<br>| species | varchar(20) | YES  |     | NULL    |       |<br>| sex     | char(1)     | YES  |     | NULL    |       |<br>| birth   | date        | YES  |     | NULL    |       |<br>| death   | date        | YES  |     | NULL    |       |<br>+---------+-------------+------+-----+---------+-------+<br>6 rows in set (0.02 sec)


使用文本来写pet表的数据, NULL值用/N来表示
我使用的是windows, 路径在windows下为c:/pet.txt, 但是在mysql下应该为c:/pet.txt或c://pet.txt
这个是转义字符, 想得到"/"需要输入"//"

LOAD DATA LOCAL INFILE 'c:/pet.txt' INTO TABLE pet;

pet.txt文件内容

Fluffy    Harold    cat    f    1993-02-04    /N<br>Claws    Gwen    cat    m    1994-03-17    /N<br>Buffy    Harold    dog    f    1989-05-13    /N<br>Fang    Benny    dog    m    1990-08-27    /N<br>Bowser    Diane    dog    m    1979-08-31    1995-07-29<br>Chirpy    Gwen    bird    f    1998-09-11    /N<br>Whistler    Gwen    bird    /N    1997-12-09    /N<br>Slim    Benny    snake    m    1996-04-29    /N


查看插入的数据
SELECT * FROM pet;

+----------+--------+---------+------+------------+------------+<br>| name     | owner  | species | sex  | birth      | death      |<br>+----------+--------+---------+------+------------+------------+<br>| Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |<br>| Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |<br>| Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |<br>| Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |<br>| Bowser   | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |<br>| Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |<br>| Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |<br>| Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |<br>+----------+--------+---------+------+------------+------------+<br>8 rows in set (0.00 sec)

作者:icejoywoo 出处:http://www.cnblogs.com/icejoywoo/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
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

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

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