博客
关于我
mysql常用命令
阅读量:793 次
发布时间: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学习总结(7)——MySql索引原理与使用大全
查看>>
Mysql学习总结(80)——统计数据库的总记录数和库中各个表的数据量
查看>>
Mysql学习总结(81)——为什么MySQL不推荐使用uuid或者雪花id作为主键?
查看>>
Mysql学习总结(82)——MySQL逻辑删除与数据库唯一性约束如何解决?
查看>>
Mysql学习总结(83)——常用的几种分布式锁:ZK分布式锁、Redis分布式锁、数据库分布式锁、基于JDK的分布式锁方案对比总结
查看>>
Mysql学习总结(84)—— Mysql的主从复制延迟问题总结
查看>>
Mysql学习总结(85)——开发人员最应该明白的数据库设计原则
查看>>
Mysql学习总结(8)——MySql基本查询、连接查询、子查询、正则表达查询讲解
查看>>
Mysql学习总结(9)——MySql视图原理讲解与使用大全
查看>>
Mysql学习笔记 - 在Centos7环境下离线安装Mysql
查看>>
MySQL学习笔记十七:复制特性
查看>>
Mysql学习第一课-mysql的定义及sql语句
查看>>
mysql安全模式: sql_safe_updates
查看>>
mysql安装,卸载,连接
查看>>
MySQL安装之没有配置向导
查看>>
mysql安装出现 conflicts with mysql*的解决办法
查看>>
mysql安装卡在最后一步解决方案(附带万能安装方案)
查看>>
mysql安装和启动命令小结
查看>>
Mysql安装教程(命令行)
查看>>
mysql安装版安装
查看>>