总结常用MySQL命令:25字(mysql常用命令总结)

MySQL客户端的常用命令总结如下:

1.连接数据库:mysql -u [user] -p

2.查看系统数据库:show databases;

3.选择一个库:use [数据库名];

4.查看数据库表:show tables;

5.查看表结构:desc [tableName];

6.查询数据表:SELECT [field] FROM [tableName];

7.查询排序数据:SELECT [field] FROM [tableName] ORDER BY [field];

8.添加字段:ALTER TABLE [tableName] ADD [field] VARCHAR(10) DEFAULT ‘OK’;

9.修改字段:ALTER TABLE [tableName] MODIFY [field] VARCHAR (20);

10.删除字段:ALTER TABLE [tableName] DROP [field];

11.插入数据:INSERT INTO [tableName] (field1, field2,…) VALUES (‘value1′,’value2’,…);

12.更新数据:UPDATE [tableName] SET [field1] = ‘value1’, [field2] = ‘value2’ WHERE [condition];

13.删除记录:DELETE FROM [tableName] WHERE [condition];

14.创建数据库:create database [databaseName];

15.删除数据库:drop database [databaseName];

16.创建数据表:CREATE TABLE [tableName] (id int(10), name varchar(20));

17.删除表:DROP TABLE [tableName];

18.创建索引:CREATE INDEX [indexName] ON [tableName] (field1);

19.删除索引:DROP INDEX [indexName];

20.重命名表:ALTER TABLE [tableName] RENAME TO [newTableName];

21.备份数据库:mysqldump -u [user] -p [dbname] > back.sql;

22.恢复数据库:mysql -u [user] -p [dbname]

23.查看用户权限:show grants for [user];

24.删除用户:drop user [user];

25.重置用户密码:SET PASSWORD FOR [user]@[host] = password(‘[password]’);


数据运维技术 » 总结常用MySQL命令:25字(mysql常用命令总结)