参考了官方文档: 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)


MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

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'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

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
