MySQL

2019-07-20  本文已影响0人  Zz鱼丸

管理MySQL的命令:

CREATE TABLE IF NOT EXISTS `runoob_tbl`(
   `runoob_id` INT UNSIGNED AUTO_INCREMENT,
   `runoob_title` VARCHAR(100) NOT NULL,
   `runoob_author` VARCHAR(40) NOT NULL,
   `submission_date` DATE,
   PRIMARY KEY ( `runoob_id` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
实例解析:

    如果你不想字段为 NULL 可以设置字段的属性为 NOT NULL, 在操作数据库时如果输入该字段的数据为NULL ,就会报错。
    AUTO_INCREMENT定义列为自增的属性,一般用于主键,数值会自动加1。
    PRIMARY KEY关键字用于定义列为主键。 您可以使用多列来定义主键,列间以逗号分隔。
    ENGINE 设置存储引擎,CHARSET 设置编码
INSERT INTO table_name ( field1, field2,...fieldN )
                       VALUES
                       ( value1, value2,...valueN );
SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[LIMIT N][ OFFSET M]

select * from runoob_tbl;
select runoob_title from runoob_tbl;
select runoob_id,runoob_title from runoob_tbl;
SELECT field1, field2,...fieldN FROM table_name1, table_name2...
[WHERE condition1 [AND [OR]] condition2.....

SELECT * from runoob_tbl WHERE runoob_author='菜鸟教程';

图片.png
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
实例
UPDATE runoob_tbl SET runoob_title='学习 C++' WHERE runoob_id=3;
DELETE FROM table_name [WHERE Clause]
实例
DELETE FROM runoob_tbl WHERE runoob_id=3;
Query OK, 1 row affected (0.23 sec)
SELECT field1, field2,...fieldN 
FROM table_name
WHERE field1 LIKE condition1 [AND [OR]] filed2 = 'somevalue'
实例
SELECT * from runoob_tbl  WHERE runoob_author LIKE '%COM';
INSERT INTO clone_tbl (runoob_id,
                       runoob_title,
                       runoob_author,
                       submission_date)
SELECT runoob_id,runoob_title,
               runoob_author,submission_date
FROM runoob_tbl;
``
#数据类型
##数值类型
![图片.png](https://img.haomeiwen.com/i7426696/e6eadc2255730327.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##日期和时间类型
![图片.png](https://img.haomeiwen.com/i7426696/7aea32c374e546bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##字符串类型
![图片.png](https://img.haomeiwen.com/i7426696/a5c34a456b796842.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
MySQL 5.0 以上的版本:
1、一个汉字占多少长度与编码有关:
UTF-8:一个汉字=3个字节
GBK:一个汉字=2个字节
2、varchar(n) 表示 n 个字符,无论汉字和英文,Mysql 都能存入 n 个字符,仅是实际字节长度有所区别
3、MySQL 检查长度,可用 SQL 语言来查看

#解决访问同网段IP的数据库错误

https://blog.csdn.net/OldTogether/article/details/79612627

问题:
同一个项目,在windows下访问本地的mysql正常运行,在同一网段的计算机上面报下面异常,java.sql.SQLException:null, message from server: "Host '192.168.0.131' is not allowed to connect.
解决方法:
use mysql;
show tables;
select host from user;
update user set host ='%' where user ='root';
重启mysql服务
上一篇下一篇

猜你喜欢

热点阅读