MySQL入门
2017-04-17 本文已影响0人
yunie
mysql -u username -p password -h host
mysql> show databases;
1. 连接到mysql
mysql -u username -p password -h host
2. 创建数据库/删除数据库
create database database_name;
drop database database_name;
3. 创建表,删除表
create table table_name
drop table table_name
4.添加字段,删除字段
alter table table_name add 字段名 varchar(10) not null;
alter table table_name drop 字段名;
5. 添加数据,删除数据
insert into table_name ( field1, field2,... fieldN )
VALUES
( value1, value2,... valueN );
delete from table_name [where Clause]
6. 关闭mysql连接
1. exit;
2. quit;
3. \q;
其他命令:(以下命令需要已连接到MySQL)
1. 修改密码
set password for username@localhost = password('newpassword');
*用户当前已登录 *
PASSWORD = PASSWORD("newpassword");
2. 创建用户
CREATE USER ''&'' IDENTIFIED BY '';
CREATE USER 'username'&'localhost' IDENTIFIED BY 'password';
localhost 设置为%表示不限制访问ip
3. 授权
GRANT privileges ON.TO ''@'host';
grant all on databasename.tablename to 'username'@'host';
4. 显示数据库
show databases;
5. 使用数据库
use databasename;
6.废弃当前命令
\c
7.显示注释
show full columns from tablename
7.显示创建表信息
show create table from tablename