博客
关于我
mysql常用命令
阅读量:792 次
发布时间: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导入(ibd文件)
查看>>
Mysql工作笔记006---Mysql服务器磁盘爆满了_java.sql.SQLException: Error writing file ‘tmp/MYfXO41p‘
查看>>
MySQL工具1:mysqladmin
查看>>
mysql常用命令
查看>>
MySQL常用命令
查看>>
mysql常用命令
查看>>
MySQL常用指令集
查看>>
mysql常用操作
查看>>
MySQL常用日期格式转换函数、字符串函数、聚合函数详
查看>>
MySQL常见函数
查看>>
MySQL常见架构的应用
查看>>
MySQL常见的三种存储引擎(InnoDB、MyISAM、MEMORY)
查看>>
MySQL常见的三种存储引擎(InnoDB、MyISAM、MEMORY)
查看>>
MySQL常见约束条件
查看>>
MySQL常见错误
查看>>
MySQL常见错误分析与解决方法总结
查看>>
mysql并发死锁案例
查看>>
MySQL幻读:大家好,我是幻读,我今天又被解决了
查看>>
MySQL底层概述—1.InnoDB内存结构
查看>>
MySQL底层概述—2.InnoDB磁盘结构
查看>>