博客
关于我
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万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
MySQL中B+Tree索引原理
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中datetime与timestamp类型有什么区别
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中null和空字符串的区别与问题!
查看>>
MySQL中ON DUPLICATE KEY UPDATE的介绍与使用、批量更新、存在即更新不存在则插入
查看>>
MYSQL中TINYINT的取值范围
查看>>
Mysql中varchar类型数字排序不对踩坑记录
查看>>
mysql中出现update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在 dpkg: 处理软件包 mysql-server-8.0的解决方法(全)
查看>>
MySQL中地理位置数据扩展geometry的使用心得
查看>>
Mysql中存储引擎简介、修改、查询、选择
查看>>
mysql中实现rownum,对结果进行排序
查看>>