服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|

服务器之家 - 数据库 - Mysql - Linux操作系统操作MySQL常用命令小结

Linux操作系统操作MySQL常用命令小结

2020-08-03 18:32medisons Mysql

本文给大家分享Linux操作系统操作MySQL常用命令小结,需要的朋友参考下吧

下面给大家分享mysql常用命令,

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- 启动数据库
service myslqd start;
-- 进入MySQL -u root -p/mysql -h localhost -u root -p DatabaseName;
-- 列出数据库
show database;
-- 创建数据库
create database XXXX;
-- 选择数据库
use DatabaseName;
-- 罗列表
show table;
-- 显示表格的属性
show columns from tablename;
-- 建立数据库
source filename.txt;
-- 增加一个字段
alter table tablename add column filename datatype;
-- 增加多个字段
alter table tablename add column filename1 datatype,add column filename2 datatype;
-- 新增一个用户
grant all On *.* to user@localhost identity by "password";
-- 查询时间
select now();
-- 查询用户
select user();
-- 查询数据库版本
select version();
-- 查询当前使用的数据库
select database();
-- 删除student_course数据库中的student数据便
rm -f student_cource/student.*
-- 备份数据库(备份数据库Apple1)
MySQLdump -u root -p Apple1>C:\Apple1.txt
-- 备份表(将数据库Apple1中的mytable表备份)
MySQLdump -u root -p mytable>C:\Apple.txt
-- 创建临时表(mytable)
create temporary table mytable(id int,address varchar(20),name varchar(20));
-- 创建表前先判断系统是否存在这个表
create table if not exists mytable(......);
-- 从已有的table1表中复制表结构到table2
create table table2 select * from table1 where 1<>1;
-- 复制表
create table table2 select * from table1;
-- 重命名表名
alter table table1 rename as table2;
-- 修改列的数据类型
alter table table1 modify ID int unsigned;--把列ID的类型修改为int unsigned
alter table table1 change ID SID int unsigned; --把列ID改名为 SID且类型改为int unsigned
-- 创建索引
alter table table1 add index Ind_id (ID);
create index ind_ID on tablename (ID);
create unique index ind_id on tablename(ID);
-- 删除索引
drop index ind_id On table1;
alter table table1 drop index ind_ID;
-- 联合查询字符与多个列连接‘
select concat(ID,':',name,'=') from table1
-----------------------第二片------------------------------------
--显示数据库
show database;
--显示数据库中的表
show tables;
--显示数据表结构
describe tablename;
--显示表记录
select * from tablename;
--查询能操作MySQL的用户
select * from user;
--创建数据库
create database databasename
--例如↓
MySQL> create database AA;
---创建表
user AA;
mysql> create table table1(ID int auto_increment not null primary key,name char(6),sex char(6),birthday date)
 ---插入几条记录
 MySQL> insert into AA values('','张三','男','1971-10-01');
 MySQL> insert into AA values('','刘佳佳','女','1978-10-01');
 --验证结果
 MySQL> select * from AA;
--修改张三的生日为1971-01-10
MySQL> update AA set birthday = '1971-01-10' where ID = '1';
--删除记录
MySQL> delete from AA where ID = '1';
--删除表以及库
mysql> drop table tablename;
MySQL> drop database databasename;
--新增万能用户
-- 格式:grant select On database.* to username@localhost identity by 'password'
用户名user_1 密码是123456
--可以自任何PC上登录这个用户对数据库为所欲为
MySQL> grant select,insert update,delete on *.* to user_1@"%" identity by "123456";
--创建只有在本机才能操作数据库的用户
用户名user_2 密码是123456
MySQL> grant select,insert update,delete on *.* to user_2@localhost identity by "123456";
--登录数据库库
MySQL> -u user_1 -p -h IP地址;

以上所述是小编给大家介绍的Linux操作系统操作MySQL常用命令小结,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://blog.csdn.net/qq_39181479/article/details/75048928

延伸 · 阅读

精彩推荐