一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

在linux下如何进行mysql命令行 创建数据库

时间:2014-04-17 编辑:简简单单 来源:一聚教程网


首选用putty连接linux服务器,进行命令行
输入mysql -u+数据库用户 -p+数据库密码
架设数据库用户是root 密码是123,应该是像下面这样才是正确的:
mysql -uroot -p123
-u和-p连接数据库用户和密码中间是不能有空格的
下面来创建数据库mydatabase
create database mydatabase;
这样一个名叫mydatabase的数据库就创建好了
show databases; 显示所有数据库列表
drop database mydatabase; 删除数据库mydatabase
那么如何退出mysql命令行呢?
在终端输入exit; 知道完全退出mysql命令行为止

附后一些常用的命令

(4) 制定TestDB数据库为当前默认数据库
mysql> use TestDB;
(5) 在TestDB数据库中创建表customers
mysql> create table customers(userid int not null, username varchar(20) not null);
(6) 显示数据库列表
mysql> show databases;
(7)显示数据库中的表
mysql> show tables;
(8)删除表customers
mysql> drop table customers;
(9)显示customers表的结构
mysql> desc customers;
(10) 向customers表中插入一条记录
mysql> insert into customers(userid, username) values(1, 'hujiahui');
(11) 让操作及时生效;
mysql> commit;
(12) 查询customers中的记录
mysql> select * from customers;
(12) 更新表中的数据
mysql> update customers set username='DennisHu' where userid=1;
(13) 删除表中的记录
mysql> delete from customers;
(14)授予hjh用户访问数据库的权限
# grant select, insert, update, delete on *.* to hjh@localhost indentified by "123456";
备注:hjh是Linux用户名,123456是访问mysql的密码
(15)采用用户名和密码登录mysql
# mysql -uhjh -p123456

热门栏目