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
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 |
| 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]; 手动一个个执行下来之后表就转到新的库里面了. |
本文介绍了MySQL数据库的基本管理操作,包括设置密码、权限配置、数据库及表的创建与删除等,并详细说明了表列的增删改操作。
1183

被折叠的 条评论
为什么被折叠?



