mysql笔记-- mysql命令札记5

本文介绍了MySQL数据库的基本管理操作,包括设置密码、权限配置、数据库及表的创建与删除等,并详细说明了表列的增删改操作。


5.1设置数据库密码

set password=password(''); 设置密码为空,在mysql的密码是42个char字符串,设置密码,需要是使用psasword();来生成;
kevin@xu:~$ mysql -uroot -p 
Enter password:****
mysql> set password=password('');
Query OK, 0 rows affected (0.00 sec)
mysql> 

5.2设置数据库访问权限

为数据库增加访问者:
mysql> grant all on firstdb.* to kevin@localhost identified by "kevin";

kevin@xu:~$ mysql -ukevin -pkevin firstdb



5.3 修改数据库信息

5.3.1 创建删除数据库
create database 数据库名称
mysql> create database testdatabase;
Query OK, 1 row affected (0.00 sec)

drop  database 数据库名称
mysql> drop database testdatabase;
Query OK, 0 rows affected (0.00 sec)
5.3.2 创建删除数据表
create table 数据表名称
mysql> create table test_n (id int(10));                          
Query OK, 0 rows affected (0.01 sec)

drop  table 数据表名称
mysql> 
mysql> drop table test_n;
Query OK, 0 rows affected (0.00 sec)

5.3.3 操作数据表 列
增加列
alter table 数据表名称 add 列名 此列类型;

mysql> alter table test_n add name varchar(20);
Query OK, 0 rows affected (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 0

修改列名

alter table 数据表名称 change 旧列名  新列名 此列类型;
mysql> alter table test_n change name name_n int(10);
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

修改列定义数据类型
alter table 数据表名称 modify 列名 此列类型;
mysql> alter table test_n modify name_n varchar(10);
Query OK, 0 rows affected (0.10 sec)
Records: 0  Duplicates: 0  Warnings: 0
5.3.4 删除数据表 列
alter table 数据表名称 drop  列名;

mysql> alter table test drop id ;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

5.3.5 重命名数据表
alter table 旧数据表名称 新数据表名称;

alter table 旧数据表名称  to 新数据表名称;

mysql> alter table test_n rename test;
Query OK, 0 rows affected (0.05 sec)

5.3.6 修改数据库名称
假设源库名是’srcdb’,目标库名是’trgdb’
首先创建目标库
create database trgdb;
获取所有源库的表名
use information_schema;
select table_name from TABLES where TABLE_SCHEMA=’srcdb’;
然后按照以下命令一个个修改
rename table srcdb.[tablename] to trgdb.[tablename];
手动一个个执行下来之后表就转到新的库里面了.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值