mysql常用命令
2007-02-03 10:57
519 查看
Mysql 命令
1. 登录数据库
mysql –h hostname –u username –p
enter password:******
2. 启动、停止数据库服务
net start mysql
net stop mysql
3. 创建用户
Grant 权限列表 on 数据库名.表名 to 用户名@主机名 identified by 口令
实例(1):授权给用户user1 所有数据库的所有权限,并且可以在任何主机连接数据库grant all privileges on *.* to user1@”localhost” identified by ‘123456’
Grant all privileges on *.* to user1@”%” identified by ‘123456’
实例(2):增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作(localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据库,只能通过MYSQL主机上的web页来访问了。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
4. 修改密码
修改密码有两种方法
1) 直接修改数据库服务器中mysql数据库的表 user
如:use mysql
Update user set password=password(“admin”) where user=’root’ and host=’localhost’;
Flush privileges;
注:flush 是清除缓存语句,
Flush PRIVILEGES 从mysql数据库授权表中重新装载权限。
2) 使用set password语句
Set password for root@localhost=password(‘123456’)
5. 创建数据库
1) 查看数据库
Show databases
2) 创建数据库
Drop database if exists studentinfo
Create database studentinfo
如果存在数据库studentinfo 则删除重新建立
6. 创建表
1) use studentinfo
drop table if exists student;
create table student(
id int not null auto_increment,
name varchar(20) not null default ‘name’,
math int not null default 60,
primary key (id));
)
Desc studentinfo 查看表结构
7. 插入操作
Insert into studentinfo values(1,’liying’,98);
Insert into studentinfo (id,name) values(1,’liying’);
可以从文件中导入数据
Load data infile ‘student.txt’ into table student
8. 查询、删除、修改操作
直接在 mysql>命令符下 运行sql语句即可
9. 修改表结构
1) 为表student增加一列english
Alter table student add (English int not null default 60);
2) 修改name的数据类型
Alter table student modify name varchar(30) not null;
3) 修改english 的默认值
Alter table student alter English set default 100
4) 删除english的默认值
Alter table student alter English drop default;
1. 登录数据库
mysql –h hostname –u username –p
enter password:******
2. 启动、停止数据库服务
net start mysql
net stop mysql
3. 创建用户
GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON {tbl_name | * | *.* | db_name.*}
TO user_name [IDENTIFIED BY 'password']
[, user_name [IDENTIFIED BY 'password'] ...]
[WITH GRANT OPTION]
Grant 权限列表 on 数据库名.表名 to 用户名@主机名 identified by 口令
实例(1):授权给用户user1 所有数据库的所有权限,并且可以在任何主机连接数据库grant all privileges on *.* to user1@”localhost” identified by ‘123456’
Grant all privileges on *.* to user1@”%” identified by ‘123456’
实例(2):增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作(localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据库,只能通过MYSQL主机上的web页来访问了。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
4. 修改密码
修改密码有两种方法
1) 直接修改数据库服务器中mysql数据库的表 user
如:use mysql
Update user set password=password(“admin”) where user=’root’ and host=’localhost’;
Flush privileges;
注:flush 是清除缓存语句,
Flush PRIVILEGES 从mysql数据库授权表中重新装载权限。
2) 使用set password语句
Set password for root@localhost=password(‘123456’)
5. 创建数据库
1) 查看数据库
Show databases
2) 创建数据库
Drop database if exists studentinfo
Create database studentinfo
如果存在数据库studentinfo 则删除重新建立
6. 创建表
1) use studentinfo
drop table if exists student;
create table student(
id int not null auto_increment,
name varchar(20) not null default ‘name’,
math int not null default 60,
primary key (id));
)
Desc studentinfo 查看表结构
7. 插入操作
Insert into studentinfo values(1,’liying’,98);
Insert into studentinfo (id,name) values(1,’liying’);
可以从文件中导入数据
Load data infile ‘student.txt’ into table student
8. 查询、删除、修改操作
直接在 mysql>命令符下 运行sql语句即可
9. 修改表结构
1) 为表student增加一列english
Alter table student add (English int not null default 60);
2) 修改name的数据类型
Alter table student modify name varchar(30) not null;
3) 修改english 的默认值
Alter table student alter English set default 100
4) 删除english的默认值
Alter table student alter English drop default;
相关文章推荐
- MySQL 常用命令
- Mysql常用命令
- MYSQL常用命令
- mysql的设置更改root密码、连接、常用命令
- 十三周三次课 2018.01.13 设置更改root密码、连接MySQL、MySQL常用命令
- MYSQL常用命令
- linux下mysql的常用命令
- mysql常用命令总结
- mysql常用命令
- Mysql 一些常用命令
- MySQL常用命令和常见问题
- mysql常用命令操作
- MYSQL常用查命令
- 设置更改root密码、连接MYSQL、MYSQL常用命令
- 常用MySQL的命令集锦
- Linux下MySQL默认安装目录和常用命令
- mysql中一些常用的命令
- mysql中一些常用的命令
- mysql中一些常用的命令
- MySQL导入.sql文件及常用命令