bitsCN.com
最近发现对于数据库知识已经忘得差不多了,我的工作基本不涉及mysql数据库
年后人心都较为浮躁,因此希望找点事情弥补空虚的灵魂。MySQL数据库以前用过
这里将其拿出来深入研究了一下用文件创建数据库的方法,也许以后用得着。
#####-----------------------mysql数据库开始(一)----------------#####
1、# 创建数据库语句
create database mydb default character set utf8;
# 运用数据库语句
use mydb;
# 创建表格,这里只简单的创建一张表格
# 设置InnoDB主要是为了事务操作的需要
create table mytable(
id int primary key auto_increment,
name varchar(20),
count int not null
)type=InnoDB;
# cmd进入数据库方法
mysql -u root -p
#输入密码进入mysql命令行
#将以上sql语句放到.sql文件中,并导入数据库,这里是windows方式
#注意:这里路径不能添加引号,只需要直接放到source后即可,否则报错
#source $path/mydb.sql
mysql> source E:/mydb.sql
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected, 1 warning (0.09 sec)
#describe mytable或者desc mytable检查表格字段是否有误
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | YES | | NULL | |
| count | int(11) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2、#向表格中导入数据或者导出数据
#首先采用.txt文本导入方式
#按照表格字段进行示例如下:
id name count
1 张三 1000
2 李四 500
3 王老虎 100
#将三组数据复制放到新建txt文本中,这么命名为:mydb.txt
mysql> load data infile 'E:/mydb.txt' into table mytable
-> fields terminated by '/t' #表示字段间距
-> lines terminated by '/n'; #表示行间距
Query OK, 3 rows affected (0.03 sec)
Records: 3 Deleted: 0 Skipped: 0 Warnings: 0
#由于数据较少这里通过简单的查询可以查看数据导入信息
mysql> select * from mytable;
+----+--------+-------+
| id | name | count |
+----+--------+-------+
| 1 | 张三 | 1000 |
| 2 | 李四 | 500 |
| 3 | 王老虎 | 100 |
+----+--------+-------+
3 rows in set (0.05 sec)
#由于Id字段是自动增加的,所以这里尝试一下不添加字段
#预编写sql语句:load data local infile 'E:/mydb.txt' into table mytable(name,count);
#导入数据为:
赵大 1000
王二小 500
三亚子 100
mysql> load data local infile 'E:/mydb.txt' into table mytable(name,count);
Query OK, 3 rows affected (0.07 sec)
Records: 3 Deleted: 0 Skipped: 0 Warnings: 0
#查询新数据,这里的方法只适合数据较小的情况
mysql> select * from mytable;
+----+--------+-------+
| id | name | count |
+----+--------+-------+
| 1 | 张三 | 1000 |
| 2 | 李四 | 500 |
| 3 | 王老虎 | 100 |
| 4 | 赵大 | 1000 |
| 5 | 王二小 | 500 |
| 6 | 三亚子 | 100 |
+----+--------+-------+
6 rows in set (0.00 sec)
#可以看到确实增加了三行数据,而且ID自增。
#这里尝试一下将表中数据导出到txt文件中,这里我们有选择的导出数据,如果全部导出与之类似
#下面方式会报错
select * into outfile 'E:/mydb1.txt'
lines terminated by '/r/n'
fields terminated by '/t'
from mytable;
#这个地方有一个奇特的现象fields行必须添加到lines上面即如下操作才不会报错:
mysql> select * into outfile 'E:/mydb1.txt'
-> fields terminated by '/t' #在此例中该行可有可无
-> lines terminated by '/r/n'
-> from mytable ;
Query OK, 6 rows affected (0.00 sec)
#导出数据并不包括表字段。
#####----------------------mysql的分割线----------------------#####
这里先介绍这些,东西不是很多,但是还是相对较为实用。

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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
