博客
关于我
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之2003-Can‘t connect to MySQL server on ‘localhost‘(10038)的解决办法
查看>>
MySQL之CRUD
查看>>
MySQL之DML
查看>>
Mysql之IN 和 Exists 用法
查看>>
Mysql之主从复制
查看>>
mysql之分组查询GROUP BY,HAVING
查看>>
mysql之分页查询
查看>>
Mysql之备份与恢复
查看>>
mysql之子查询
查看>>
MySQL之字符串函数
查看>>
mysql之常见函数
查看>>
Mysql之性能优化--索引的使用
查看>>
mysql之旅【第一篇】
查看>>
Mysql之索引选择及优化
查看>>
mysql之联合查询UNION
查看>>
mysql之连接查询,多表连接
查看>>
mysql乱码
查看>>
Mysql事务。开启事务、脏读、不可重复读、幻读、隔离级别
查看>>
MySQL事务与锁详解
查看>>
MySQL事务原理以及MVCC详解
查看>>