search
HomeDatabaseMysql TutorialMySQL常用命令行总结收集

MySQL常用命令行总结收集

Jun 07, 2016 pm 04:22 PM
mysqlCommand LineCommonly usedSummarizecollect

第一招、mysql服务的启动和停止 net stop mysql net start mysql 第二招、登陆mysql 语法如下: mysql -u用户名 -p用户密码 键入命令mysql -uroot -p, 回车后提示你输入密码,输入12345,然后回车即可进入到mysql中了,mysql的提示符是: mysql 注意,如果

   第一招、mysql服务的启动和停止

  net stop mysql

  net start mysql

  第二招、登陆mysql

  语法如下: mysql -u用户名 -p用户密码

  键入命令mysql -uroot -p, 回车后提示你输入密码,输入12345,然后回车即可进入到mysql中了,mysql的提示符是:

  mysql>

  注意,如果是连接到另外的机器上,则需要加入一个参数-h机器IP

  第三招、增加新用户

  格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"

  如,增加一个用户user1密码为password1,让其可以在本机上登录, 并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入mysql,,然后键入以下命令:

  grant select,insert,update,delete on *.* to user1@localhost Identified by "password1";

  如果希望该用户能够在任何机器上登陆mysql,则将localhost改为"%"。

  如果你不想user1有密码,可以再打一个命令将密码去掉。

  grant select,insert,update,delete on mydb.* to user1@localhost identified by "";

  第四招: 操作数据库

  登录到mysql中,然后在mysql的提示符下运行下列命令,每个命令以分号结束。

  1、 显示数据库列表。

  show databases;

  缺省有两个数据库:mysql和test。 mysql库存放着mysql的系统和用户权限信息,我们改密码和新增用户,实际上就是对这个库进行操作。

  2、 显示库中的数据表:

  use mysql;

  show tables;

  3、 显示数据表的结构:

  describe 表名;

  4、 建库与删库:

  create database 库名;

  drop database 库名;

  5、 建表:

  use 库名;

  create table 表名(字段列表);

  drop table 表名;

  6、 清空表中记录:

  delete from 表名;

  7、 显示表中的记录:

  select * from 表名;

  第五招、导出和导入数据

  1. 导出数据:

  mysqldump --opt test > mysql.test

  即将数据库test数据库导出到mysql.test文件,后者是一个文本文件

  如:mysqldump -u root -p123456 --databases dbname > mysql.dbname

  就是把数据库dbname导出到文件mysql.dbname中。

  2. 导入数据:

  mysqlimport -u root -p123456

  不用解释了吧。

  3. 将文本数据导入数据库:

  文本数据的字段数据之间用tab键隔开。

  use test;

  load data local infile "文件名" into table 表名;

  1:使用SHOW语句找出在服务器上当前存在什么数据库:

  mysql> SHOW DATABASES;

  2:2、创建一个数据库MYSQLDATA

  mysql> CREATE DATABASE MYSQLDATA;

  3:选择你所创建的数据库

  mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功!)

  4:查看现在的数据库中存在什么表

  mysql> SHOW TABLES;

  5:创建一个数据库表

  mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));

  6:显示表的结构:

  mysql> DESCRIBE MYTABLE;

  7:往表中加入记录

  mysql> insert into MYTABLE values ("hyq","M");

  8:用文本方式将数据装入数据库表中(例如D:/mysql.txt)

  mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;

  9:导入.sql文件命令(例如D:/mysql.sql)

  mysql>use database;

  mysql>source d:/mysql.sql;

  10:删除表

  mysql>drop TABLE MYTABLE;

  11:清空表

  mysql>delete from MYTABLE;

  12:更新表中数据

  mysql>update MYTABLE set sex="f" where;

Statement
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
When should you use a composite index versus multiple single-column indexes?When should you use a composite index versus multiple single-column indexes?Apr 11, 2025 am 12:06 AM

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)Apr 10, 2025 am 09:36 AM

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL: Essential Skills for DevelopersMySQL and SQL: Essential Skills for DevelopersApr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

Describe MySQL asynchronous master-slave replication process.Describe MySQL asynchronous master-slave replication process.Apr 10, 2025 am 09:30 AM

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL: Simple Concepts for Easy LearningMySQL: Simple Concepts for Easy LearningApr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL: A User-Friendly Introduction to DatabasesMySQL: A User-Friendly Introduction to DatabasesApr 10, 2025 am 09:27 AM

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

How does the InnoDB Buffer Pool work and why is it crucial for performance?How does the InnoDB Buffer Pool work and why is it crucial for performance?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL: The Ease of Data Management for BeginnersMySQL: The Ease of Data Management for BeginnersApr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)