mysql数据库的文件创建方式
最近发现对于数据库知识已经忘得差不多了,我的工作基本不涉及mysql数据库 年后人心都较为浮躁,因此希望找点事情弥补空虚的灵魂。MySQL数据库以前用过 这里将其拿出来深入研究了一下用文件创建数据库的方法,也许以后用得着。 #####-----------------------
最近发现对于数据库知识已经忘得差不多了,我的工作基本不涉及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的分割线----------------------#####
这里先介绍这些,东西不是很多,但是还是相对较为实用。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

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.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

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.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.
