常用的MySQL命令的实际操作流程
以下的文章主要介绍的是MySQL数据库中经常使用的MySQL命令的实际操作其中包括对如何正确连接到本机上的MySQL数据库,如何正确修改密码,以及如何增加新用户的实际操作步骤,以下就是文章的具体内容。 一、连接到本机上的MySQL。 首 先打开DOS窗口,然后进入
以下的文章主要介绍的是MySQL数据库中经常使用的MySQL命令的实际操作其中包括对如何正确连接到本机上的MySQL数据库,如何正确修改密码,以及如何增加新用户的实际操作步骤,以下就是文章的具体内容。
一、连接到本机上的MySQL。
首 先打开DOS窗口,然后进入目录MySQL\bin,再键入MySQL命令MySQL -u root -p,回车后提示你输密码.注意用户名前可以有空格也可以没有空格,但是密码前必须没有空格,否则让你重新输入密码.
如果刚安装好MySQL,超级用户root是没有密码的,故直接回车即可进入到 MySQL中了,MySQL的提示符是: MySQL>
2、连接到远程主机上的MySQL。假设远程主机的IP 为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命令:
MySQL -h110.110.110.110 -u root -p 123; (注:u与root之间可以不用加空格,其它也一样)
3、退出MySQL命令: exit (回车)
二、修改密码。
格 式:MySQLadmin -u用户名 -p旧密码 password 新密码
1、给root加个密码ab12。首先在DOS下进入目录 MySQL\bin,然后键入以下命令
MySQLadmin -u root -password ab12
注:因为开始时root没有 密码,所以-p旧密码一项就可以省略了。
2、再将root的密码改为djg345。
MySQLadmin -u root -p ab12 password djg345
三、 增加新用户。
(注意:和上面不同,下面的因为是MySQL环境中的命令,所以后面都带一个分号作为命令结束符)
格 式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”
1、增加一个用户test1密 码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用root用户连入MySQL,然后键入以下命令:
1 |
|
但 增加的用户是十分危险的,你想如某个人知道test1的密码,那么他就可以在internet上的任何一台电脑上登录你的MySQL数据库并对你的数据可 以为所欲为了,解决办法见2。
2、增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查 询、插入、修改、删除的操作(localhost指本地主机,即MySQL数据库所在的那台主机),
这样用户即使用知道test2的密码,他也无 法从internet上直接访问数据库,只能通过MySQL主机上的web页来访问了。
1 |
|
如 果你不想test2有密码,可以再打一个MySQL命令将密码消掉。
1 |
|
下篇我们讲述的是MySQL中有关数据库方面的操作。注意:你必须首先登录到MySQL中,以下操作都是在MySQL的提示符下进行的,而且每个命令以分号结束。
一、 操作技巧
1、如果你打命令时,回车后发现忘记加分号,你无须重打一遍命令,只要打个分号回车就可以了。
也就是说你可以把一个完整的命令分 成几行来打,完后用分号作结束标志就OK。
2、你可以使用光标上下键调出以前的MySQL命令。
二、显示命令
1、显示当前数据库服务器中的 数据库列表:
1 |
|
注意:MySQL库里面有MySQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。
2、显示数据库中的数据表:
1 2 3 4 5 6 |
|
3、 显示数据表的结构:
1 |
|
4、建立数据库:
1 |
|
5、建立数据表:
1 2 3 4 5 6 |
|
6、删除数据库:
1 |
|
7、 删除数据表:
1 |
|
8、将表中记录清空:
1 |
|
9、显示表中的记录:
1 |
|
10、往表中插入记录:
1 |
|
11、更新表中数据:
1 |
|
12、用文本方式将数据装入数据表中:
1 |
|
13、导入.sql文件命令:
1 2 3 4 5 6 |
|
14、 MySQL命令行修改root密码:
1 2 3 4 5 6 |
|
15、显示use的数据库名:
1 |
|
16、 显示当前的user:
1 |
|
三、一个建库和建表以及插入数据的实例
1 |
|
如果存在SCHOOL则删除
1 |
|
建立库SCHOOL
1 |
|
打开 库SCHOOL
1 |
|
建立表TEACHER
1 2 3 4 5 6 7 8 |
|
建表结束
以下为插入字段
1 2 3 4 |
|
如果你在MySQL提示符键入上面的命令也可以,但不方便调试。
(1)你可以将以上命令原样写入一个 文本文件中,假设为school.sql,然后复制到c:\\下,并在DOS状态进入目录[url=file://\\MySQL\\bin] \\MySQL\\bin[/url],然后键入以下命令:
MySQL -uroot -p密码
如 果成功,空出一行无任何显示;如有错误,会有提示。(以上命令已经调试,你只要将//的注释去掉即可使用)。
(2)或者进入命令行后使 用 MySQL> source c:\\school.sql; 也可以将school.sql文件导入数据库中。
四、将文本数据转到数 据库中
1、文本数据应符合的格式:字段数据之间用tab键隔开,null值用[url=file://\\n]\\n[/url]来代替.例:
3 rose 大 连二中 1976-10-10
4 mike 大连一中 1975-12-23
假设你把这两组数据存为school.txt文件,放在c盘根目录下。
2、数据传入MySQL命令
1 |
|
注 意:你最好将文件复制到[url=file://\\MySQL\\bin]\\MySQL\\bin[/url]目录下,并且要先用use命令打表所在 的库。
五、备份数据库:(命令在DOS的[url=file://\\MySQL\\bin]\\MySQL\\bin[/url]目录下执行)
1. 导出整个数据库
导出文件默认是存在MySQL\bin目录下
MySQLdump -u 用户名 -p 数据库名 > 导出的文件名
1 |
|
2. 导出一个表
MySQLdump -u 用户名 -p 数据库名 表名> 导出的文件名
1 |
|
3. 导出一个数据库结构
1 |
|
-d 没 有数据 –add-drop-table 在每个create语句之前增加一个drop table
4.带语言参数导出
1 |
|
六、数据库远程登录权限设置
1 |
|
以上的相关内容就是对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

AI Hentai Generator
Generate AI Hentai for free.

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



When MySQL modifys table structure, metadata locks are usually used, which may cause the table to be locked. To reduce the impact of locks, the following measures can be taken: 1. Keep tables available with online DDL; 2. Perform complex modifications in batches; 3. Operate during small or off-peak periods; 4. Use PT-OSC tools to achieve finer control.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

The MySQL primary key cannot be empty because the primary key is a key attribute that uniquely identifies each row in the database. If the primary key can be empty, the record cannot be uniquely identifies, which will lead to data confusion. When using self-incremental integer columns or UUIDs as primary keys, you should consider factors such as efficiency and space occupancy and choose an appropriate solution.

MySQL can handle multiple concurrent connections and use multi-threading/multi-processing to assign independent execution environments to each client request to ensure that they are not disturbed. However, the number of concurrent connections is affected by system resources, MySQL configuration, query performance, storage engine and network environment. Optimization requires consideration of many factors such as code level (writing efficient SQL), configuration level (adjusting max_connections), hardware level (improving server configuration).

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

MySQL can return JSON data. The JSON_EXTRACT function extracts field values. For complex queries, you can consider using the WHERE clause to filter JSON data, but pay attention to its performance impact. MySQL's support for JSON is constantly increasing, and it is recommended to pay attention to the latest version and features.

MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.
