博客
关于我
mysql常用命令
阅读量:794 次
发布时间:2023-02-12

本文共 2104 字,大约阅读时间需要 7 分钟。

MySQL Database Operations Guide

1. MySQL Service Management

Starting MySQL Service

To start the MySQL service, use the following commands:

net start mysql

Stopping MySQL Service

To stop the MySQL service, use:

net stop mysql

2. Logging into MySQL

To access the MySQL database, use the following command:

mysql -u username -p
  • Replace username with your MySQL username.
  • If prompted, enter your password.
  • Note: For remote access, include the server IP address:
mysql -h ip_address -u username -p

3. Managing Users

Adding a New User

To create a new user with specific permissions, use the grant command:

grant select,insert,update,delete on *.* to newuser@localhost identified by "newpassword";
  • Replace newuser and newpassword with your desired username and password.
  • For remote access, replace localhost with % to allow login from any machine.

Removing Password

If you want to remove the password for a user:

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

4. Database Operations

Listing Databases

To view a list of available databases:

show databases;
  • Note: The default databases are mysql and test.

Listing Tables

To see the tables in a database:

use mysql;show tables;

Describing Table Structure

To view the structure of a table:

describe table_name;

Creating/Dropping Databases

  • Create a database:
create database dbname;
  • Drop a database:
drop database dbname;

Managing Tables

  • Create a table:
use dbname;create table table_name (column_definitions);
  • Drop a table:
drop table table_name;

Inserting and Retrieving Data

  • Insert data into a table:
insert into table_name values (data);
  • Retrieve data from a table:
select * from table_name;

Truncating a Table

To clear all data in a table:

delete from table_name;

5. Backing Up Databases

Using mysqldump

To create a backup:

mysqldump -u root -p dbname > backup.sql;
  • Replace dbname with the database you want to backup.

6. Remote MySQL Access

For remote connections, use the following command:

mysql -h remote_ip -u root -p
  • Replace remote_ip with the target server's IP address.

7. Exiting MySQL

To exit the MySQL prompt:

exit

转载地址:http://nudfk.baihongyu.com/

你可能感兴趣的文章
mysql并发死锁案例
查看>>
MySQL底层概述—1.InnoDB内存结构
查看>>
MySQL底层概述—2.InnoDB磁盘结构
查看>>
MySQL底层概述—3.InnoDB线程模型
查看>>
MySQL底层概述—4.InnoDB数据文件
查看>>
MySQL底层概述—5.InnoDB参数优化
查看>>
MySQL底层概述—6.索引原理
查看>>
MySQL底层概述—7.优化原则及慢查询
查看>>
MySQL底层概述—8.JOIN排序索引优化
查看>>
MySQL底层概述—9.ACID与事务
查看>>
Mysql建立中英文全文索引(mysql5.7以上)
查看>>
mysql建立索引的几大原则
查看>>
Mysql建表中的 “FEDERATED 引擎连接失败 - Server Name Doesn‘t Exist“ 解决方法
查看>>
MySQL开源工具推荐,有了它我卸了珍藏多年Nactive!
查看>>
MySQL异步操作在C++中的应用
查看>>
MySQL引擎讲解
查看>>
Mysql当前列的值等于上一行的值累加前一列的值
查看>>
MySQL当查询的时候有多个结果,但需要返回一条的情况用GROUP_CONCAT拼接
查看>>
MySQL必知必会(组合Where子句,Not和In操作符)
查看>>
MySQL必知必会总结笔记
查看>>