Home Database Mysql Tutorial MySQL数据库在实际应用一些方面的介绍

MySQL数据库在实际应用一些方面的介绍

Jun 07, 2016 pm 04:09 PM
mysql introduce actual application database

此篇文章主要介绍的是MySQL数据库实际应用方面的操作。但是你必须要先登录到 MySQL数据库中,下面的操作是在MySQL数据库的实际提示符之下进行的,同时也要求每个相关命令以分号结束。 一、操作技巧 1、如果你打命令时,回车后发现忘记加分号,你无须重打一遍

此篇文章主要介绍的是MySQL数据库实际应用方面的操作。但是你必须要先登录到 MySQL数据库中,下面的操作是在MySQL数据库的实际提示符之下进行的,同时也要求每个相关命令以分号结束。

一、操作技巧

1、如果你打命令时,回车后发现忘记加分号,你无须重打一遍命令,只要打个分号回车就可以了。

也就是说你可以把一个完整的命令分成几行来打,完后用分号作结束标志就OK。

2、你可以使用光标上下键调出以前的命令。

二、显示命令

1、显示当前MySQL数据库服务器中的数据库列表:

MySQL> SHOW DATABASES;

注意:MySQL库里面有MySQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。

2、显示MySQL数据库中的数据表:

MySQL> USE 库名;

MySQL> SHOW TABLES;

3、显示数据表的结构:

MySQL> DESCRIBE 表名;

4、建立MySQL数据库:

MySQL> CREATE DATABASE 库名;

5、建立数据表:

MySQL> USE 库名;

MySQL> CREATE TABLE 表名 (字段名 VARCHAR(20), 字段名 CHAR(1));

6、删除MySQL数据库:

MySQL> DROP DATABASE 库名;

7、删除数据表:

MySQL> DROP TABLE 表名;

8、将表中记录清空:

MySQL> DELETE FROM 表名;

9、显示表中的记录:

MySQL> SELECT * FROM 表名;

10、往表中插入记录:

MySQL> INSERT INTO 表名 VALUES (”hyq”,”M”);

11、更新表中数据:

MySQL-> UPDATE 表名 SET 字段名1=’a',字段名2=’b’ WHERE 字段名3=’c';

12、用文本方式将数据装入数据表中:

MySQL> LOAD DATA LOCAL INFILE “D:/MySQL.txt” INTO TABLE 表名;

13、导入.sql文件命令:

MySQL> USE 数据库名;

MySQL> SOURCE d:/MySQL.sql;

14、命令行修改root密码:

MySQL> UPDATE MySQL.user SET password=PASSWORD(’新密码’) WHERE User=’root’;

MySQL> FLUSH PRIVILEGES;

15、显示use的MySQL数据库名:

MySQL> SELECT DATABASE();

16、显示当前的user:

MySQL> SELECT USER();

三、一个建库和建表以及插入数据的实例

drop database if exists school; //如果存在SCHOOL则删除

create database school; //建立库SCHOOL

use school; //打开库SCHOOL

create table teacher //建立表TEACHER

(

id int(3) auto_increment not null primary key,

name char(10) not null,

address varchar(50) default ‘深圳’,

year date

); //建表结束

//以下为插入字段

insert into teacher values(”,’allen’,'大连一中’,'1976-10-10′);

insert into teacher values(”,’jack’,'大连二中’,'1975-12-23′);

如果你在MySQL提示符键入上面的命令也可以,但不方便调试。

(1)你可以将以上命令原样写入一个文本文件中,假设为school.sql,然后复制到c:\下,并在DOS状态进入目录[url=file://\MySQL\bin]\MySQL\bin[/url],然后键入以下命令:

MySQL -uroot -p密码

如果成功,空出一行无任何显示;如有错误,会有提示。(以上命令已经调试,你只要将//的注释去掉即可使用)。

(2)或者进入命令行后使用 MySQL> source c:\school.sql; 也可以将school.sql文件导入数据库中。

四、将文本数据转到MySQL数据库中

1、文本数据应符合的格式:字段数据之间用tab键隔开,null值用[url=file://\n]\n[/url]来代替.例:

3 rose 大连二中 1976-10-10

4 mike 大连一中 1975-12-23

假设你把这两组数据存为school.txt文件,放在c盘根目录下。

2、数据传入命令 load data local infile “c:\school.txt” into table 表名;

注意:你最好将文件复制到[url=file://\MySQL\bin]\MySQL\bin[/url]目录下,并且要先用use命令打表所在的库。

五、备份数据库:(命令在DOS的[url=file://\MySQL\bin]\MySQL\bin[/url]目录下执行)

1.导出整个数据库

导出文件默认是存在MySQLbin目录下

MySQLdump -u 用户名 -p 数据库名 > 导出的文件名

MySQLdump -u user_name -p123456 database_name > outfile_name.sql

2.导出一个表

MySQLdump -u 用户名 -p MySQL数据库名 表名> 导出的文件名

MySQLdump -u user_name -p database_name table_name > outfile_name.sql

3.导出一个MySQL数据库结构

MySQLdump -u user_name -p -d –add-drop-table database_name > outfile_name.sql

-d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table

4.带语言参数导出

MySQLdump -uroot -p –default-character-set=latin1 –set-charset=gbk –skip-opt database_name > outfile_name.sql


 


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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Detailed introduction of Samsung S24ai functions Detailed introduction of Samsung S24ai functions Jun 24, 2024 am 11:18 AM

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

See all articles