美文网首页
python 学习笔记16(mysql)2018-5-8

python 学习笔记16(mysql)2018-5-8

作者: 我是帅气的石头 | 来源:发表于2018-05-09 21:12 被阅读0次

创建超级用户

 grant all privileges on *.* to 'szm'@'%'identified by 'password' with grant option  

创建了szm和密码password的用户:
*.*表示可以对所有数据表操作,szm创建的用户名,'%'允许任意主机链接szm用户,password密码;

grant all privileges on *.* to 'tom'@'localhost'identified by 'password' with grant option

@'localhost'创建了只用于从本机连接时帐号

设置帐号和密码

mysqladmin -u user_name -h host_name password "newpwd"

查看库

 show databases;
image.png

查看某个库的表

use shop;
 show tables;
image.png

查看表的字段

 desc message;
image.png

查看建表语句

show create table message;
image.png

查看当前是那个用户

 select user();
image.png

查看当前是那个库

select database();
image.png

查看数据库版本

select version();
image.png

查看mysql状态

show status;

创建库

create database pythondb;

创建表

 CREATE TABLE `message` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `msg` text,
  `sender` varchar(32) NOT NULL DEFAULT '',
  `receiver` varchar(32) NOT NULL DEFAULT '',
  `color` char(7) NOT NULL DEFAULT '',
  `biaoqing` varchar(32) NOT NULL DEFAULT '',
  `add_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 

查看新建的表show tables;可以看到有个新表message


image.png

插入数据

 insert into message(`msg`,`sender`,`receiver`,`color`)value('new message','asdf','join','yellow'); 

查询数据

select * from message;
image.png

更新数据表字段

 update message set msg ='old mess' where id =25;
image.png

清空表

truncate table message;
image.png

删除表

drop table message; 
image.png

删除库

drop database pythondb;

相关文章

网友评论

      本文标题:python 学习笔记16(mysql)2018-5-8

      本文链接:https://www.haomeiwen.com/subject/ygvorftx.html