本文連接:https://blog.csdn.net/root__oo7/article/details/82817501mysql
安裝:
[root@bogon ~]# yum install mariadb -y #客戶端
[root@bogon ~]# yum install mariadb-server -y #服務端
啓動服務:
[root@bogon ~]# systemctl start mariadb
[root@bogon ~]# ss -tnl | grep 3306 #查看端口肯定是否被監聽
LISTEN 0 50 *:3306 *:*
說明:如果mysql啓動 將mariadb改成mysql便可
進入mariadb:
[root@bogon ~]# mysql #注意
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
初始化mariadb:
[root@bogon ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #直接回車便可
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y #是否設置mariadb中root用戶的密碼
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y #刪除匿名用戶
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n #是否容許root遠程鏈接
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y #是否刪除test這個測試庫
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y #是否從新加載權限表
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
數據庫及表的查詢:
MariaDB [(none)]> show databases; #數據庫的查詢
+--------------------+
| Database |
+--------------------+
| hellodb |
| information_schema |
| mage |
| mysql |
| performance_schema |
+--------------------+
5 rows in set (0.16 sec)
MariaDB [(none)]> use hellodb; #進入指定的數據庫
Database changed
MariaDB [hellodb]> show tables; #數據庫中表的查詢
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.07 sec)
MariaDB [hellodb]> desc classes; #表的描述
+----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+----------------+
| ClassID | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
| Class | varchar(100) | YES | | NULL | |
| NumOfStu | smallint(5) unsigned | YES | | NULL | |
+----------+----------------------+------+-----+---------+----------------+
3 rows in set (0.14 sec)
MariaDB [hellodb]> select * from classes; #查詢表的所有內容
+---------+----------------+----------+
| ClassID | Class | NumOfStu |
+---------+----------------+----------+
| 1 | Shaolin Pai | 10 |
| 2 | Emei Pai | 7 |
| 3 | QingCheng Pai | 11 |
| 4 | Wudang Pai | 12 |
| 5 | Riyue Shenjiao | 31 |
| 6 | Lianshan Pai | 27 |
| 7 | Ming Jiao | 27 |
| 8 | Xiaoyao Pai | 15 |
+---------+----------------+----------+
8 rows in set (0.05 sec)
MariaDB [hellodb]> select class from classes; #查詢表的指定列
+----------------+
| class |
+----------------+
| Shaolin Pai |
| Emei Pai |
| QingCheng Pai |
| Wudang Pai |
| Riyue Shenjiao |
| Lianshan Pai |
| Ming Jiao |
| Xiaoyao Pai |
+----------------+
8 rows in set (0.05 sec)
MariaDB [hellodb]> select * from classes where classid=2; #按條件查詢
+---------+----------+----------+
| ClassID | Class | NumOfStu |
+---------+----------+----------+
| 2 | Emei Pai | 7 |
+---------+----------+----------+
1 row in set (0.08 sec)
數據庫及表的建立:
MariaDB [(none)]> create database zxl; #數據庫的建立
Query OK, 1 row affected (0.20 sec)
MariaDB [(none)]> show databases; #顯示庫
+--------------------+
| Database |
+--------------------+
| hellodb |
| information_schema |
| mage |
| mysql |
| performance_schema |
| zxl |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]> use zxl; #進入指定的庫
Database changed
MariaDB [zxl]> show tables; #顯示庫裏的表
Empty set (0.00 sec)
MariaDB [zxl]> create table M33; #不指定列的狀況下表的建立是不能夠的
ERROR 1113 (42000): A table must have at least 1 column
MariaDB [zxl]> create table M33(id tinyint unsigned primary key,name varchar(20)); #建立表(主鍵在此能夠定義,但不是僅能夠在此定義)
Query OK, 0 rows affected (0.33 sec)
MariaDB [zxl]> show tables; #顯示全部的表
+---------------+
| Tables_in_zxl |
+---------------+
| M33 |
+---------------+
1 row in set (0.00 sec)
MariaDB [zxl]> desc M33; #描述表
+-------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+-------+
| id | tinyint(3) unsigned | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+---------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
表數據的增刪改:
MariaDB [zxl]> insert into M33 values(1,'zhangsan'); #數據的插入
Query OK, 1 row affected (0.08 sec)
MariaDB [zxl]> select * from M33;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
MariaDB [zxl]> insert into M33 (id) values(2); #插入指定列的數據
Query OK, 1 row affected (0.09 sec)
MariaDB [zxl]> select * from M33;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
| 2 | NULL |
+----+----------+
2 rows in set (0.00 sec)
MariaDB [zxl]> insert into M33 (name) values ('lisi'); #主鍵不能爲空且惟一,因此這樣插入數據不成功
ERROR 1364 (HY000): Field 'id' doesn't have a default value
MariaDB [zxl]> select * from M33; #刪除數據前的表
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
| 2 | NULL |
+----+----------+
2 rows in set (0.00 sec)
MariaDB [zxl]> delete from M33 where id=2; #刪除指定的行數據,若是沒有where的限制條件,那麼表的內容將所有清空
Query OK, 1 row affected (0.02 sec)
MariaDB [zxl]> select * from M33; #刪除後數據的顯示
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
MariaDB [zxl]> update M33 set name='lisi' where id=1; #修改指定行的指定列的內容
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [zxl]> select * from M33;
+----+------+
| id | name |
+----+------+
| 1 | lisi |
+----+------+
1 row in set (0.00 sec)
簡單函數的運用:
MariaDB [hellodb]> select avg(age) age from students; #平均age的函數,avg(age) age中括號外的age是別名,完整的寫法爲avg(age) as age ,其中這個as能夠省略
+---------+
| age |
+---------+
| 28.2000 |
+---------+
1 row in set (0.00 sec)
MariaDB [hellodb]> select gender, avg(age) age from students group by gender; #分組求平均
+--------+---------+
| gender | age |
+--------+---------+
| F | 26.7000 |
| M | 29.2000 |
+--------+---------+
2 rows in set (0.00 sec)
MariaDB [hellodb]> select gender, avg(age) age from students where age>20 group by gender; #在where限制條件後再求分組的平均
+--------+---------+
| gender | age |
+--------+---------+
| F | 30.1429 |
| M | 36.2222 |
+--------+---------+
2 rows in set (0.00 sec)
說明:除了avg還有abs求絕對值 max最大值min最小值 sum和等的函數,其用法一致
錶鏈接:
MariaDB [hellodb]> desc students;
+-----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------------+------+-----+---------+----------------+
| StuID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| Name | varchar(50) | NO | | NULL | |
| Age | tinyint(3) unsigned | NO | | NULL | |
| phone | char(11) | YES | | NULL | |
| Gender | enum('F','M') | NO | | NULL | |
| ClassID | tinyint(3) unsigned | YES | | NULL | |
| TeacherID | int(10) unsigned | YES | | NULL | |
+-----------+---------------------+------+-----+---------+----------------+
7 rows in set (0.04 sec)
MariaDB [hellodb]> desc classes;
+----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+----------------+
| ClassID | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
| Class | varchar(100) | YES | | NULL | |
| NumOfStu | smallint(5) unsigned | YES | | NULL | |
+----------+----------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
MariaDB [hellodb]> select students.name ,classes.class from students join classes on students.classid=classes.classid;
+----------------+----------------+
| name | class |
+----------------+----------------+
| Hou Yi | Emei Pai |
| Ya Se | Shaolin Pai |
| An Qila | Emei Pai |
| Da Ji | Wudang Pai |
| Sun Shangxiang | QingCheng Pai |
| Huang Zhong | Riyue Shenjiao |
| Liu Bei | QingCheng Pai |
| Guan Yu | Ming Jiao |
| Zhang Fei | Lianshan Pai |
| Di Renjie | QingCheng Pai |
| Li Yuanfang | Lianshan Pai |
| Lan Lingwang | Shaolin Pai |
| Wang Zhaojun | Emei Pai |
| Bai Qi | QingCheng Pai |
| A Ke | Wudang Pai |
| Cai Wenji | Shaolin Pai |
| Lv Bu | Wudang Pai |
| Diao Chan | Ming Jiao |
| Gong Sunli | Lianshan Pai |
| Ming Shiyin | Ming Jiao |
| Dun Shan | Lianshan Pai |
| Zhou Yu | Shaolin Pai |
| Mi Yue | Wudang Pai |
+----------------+----------------+
23 rows in set (0.00 sec)
#上邊是兩錶鏈接
MariaDB [hellodb]> desc classes;
+----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+----------------+
| ClassID | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
| Class | varchar(100) | YES | | NULL | |
| NumOfStu | smallint(5) unsigned | YES | | NULL | |
+----------+----------------------+------+-----+---------+----------------+
3 rows in set (0.03 sec)
MariaDB [hellodb]> desc courses;
+----------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+----------------+
| CourseID | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| Course | varchar(100) | NO | | NULL | |
+----------+----------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
MariaDB [hellodb]> desc students;
+-----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------------+------+-----+---------+----------------+
| StuID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| Name | varchar(50) | NO | | NULL | |
| Age | tinyint(3) unsigned | NO | | NULL | |
| phone | char(11) | YES | | NULL | |
| Gender | enum('F','M') | NO | | NULL | |
| ClassID | tinyint(3) unsigned | YES | | NULL | |
| TeacherID | int(10) unsigned | YES | | NULL | |
+-----------+---------------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)
MariaDB [hellodb]> select s.name as student_name, co.course as course from students s join coc c on s.classid=c.classid join courses co on c.courseid=co.courseid;
+----------------+----------------------+
| student_name | course |
+----------------+----------------------+
| Hou Yi | Kuihua Baodian |
| Hou Yi | Dugu Jiujian |
| Ya Se | Kuihua Baodian |
| Ya Se | Xixing Dafa |
| An Qila | Kuihua Baodian |
| An Qila | Dugu Jiujian |
| Da Ji | Xixing Dafa |
| Da Ji | Kuihua Baodian |
| Sun Shangxiang | Hama Gong |
| Sun Shangxiang | Dagou Bangfa |
| Huang Zhong | Hama Gong |
| Liu Bei | Hama Gong |
| Liu Bei | Dagou Bangfa |
| Guan Yu | Taiji Quan |
| Guan Yu | XiangLong Shibazhang |
| Zhang Fei | XiangLong Shibazhang |
| Zhang Fei | Taiji Quan |
| Di Renjie | Hama Gong |
| Di Renjie | Dagou Bangfa |
| Li Yuanfang | XiangLong Shibazhang |
| Li Yuanfang | Taiji Quan |
| Lan Lingwang | Kuihua Baodian |
| Lan Lingwang | Xixing Dafa |
| Wang Zhaojun | Kuihua Baodian |
| Wang Zhaojun | Dugu Jiujian |
| Bai Qi | Hama Gong |
| Bai Qi | Dagou Bangfa |
| A Ke | Xixing Dafa |
| A Ke | Kuihua Baodian |
| Cai Wenji | Kuihua Baodian |
| Cai Wenji | Xixing Dafa |
| Lv Bu | Xixing Dafa |
| Lv Bu | Kuihua Baodian |
| Diao Chan | Taiji Quan |
| Diao Chan | XiangLong Shibazhang |
| Gong Sunli | XiangLong Shibazhang |
| Gong Sunli | Taiji Quan |
| Ming Shiyin | Taiji Quan |
| Ming Shiyin | XiangLong Shibazhang |
| Dun Shan | XiangLong Shibazhang |
| Dun Shan | Taiji Quan |
| Zhou Yu | Kuihua Baodian |
| Zhou Yu | Xixing Dafa |
| Mi Yue | Xixing Dafa |
| Mi Yue | Kuihua Baodian |
+----------------+----------------------+
45 rows in set (0.00 sec)
#三表鏈接
mysql> select students.name ,teachers.name from students left join teas on teachers.tid=students.teacherid;
+----------------+---------------+
| name | name |
+----------------+---------------+
| Hou Yi | Wu Zetian |
| Ya Se | NULL |
| An Qila | NULL |
| Da Ji | Cheng Jisihan |
| Sun Shangxiang | Liu Bang |
| Huang Zhong | NULL |
| Liu Bei | NULL |
| Guan Yu | NULL |
| Zhang Fei | NULL |
| Di Renjie | NULL |
| Li Yuanfang | NULL |
| Lan Lingwang | NULL |
| Wang Zhaojun | NULL |
| Bai Qi | NULL |
| A Ke | NULL |
| Cai Wenji | NULL |
| Lv Bu | NULL |
| Diao Chan | NULL |
| Gong Sunli | NULL |
| Ming Shiyin | NULL |
| Dun Shan | NULL |
| Zhou Yu | NULL |
| Mi Yue | NULL |
| Kai | NULL |
| Sun Wukong | NULL |
+----------------+---------------+
25 rows in set (0.00 sec)
說明:左鏈接就是以左邊的表爲主體,其顯示匹配的信息和爲匹配的信息都會顯示
視圖:
mysql> create view view_name_age as select name,age from students; #視圖的建立
mysql> select * from view_naem_age; #查詢視圖
mysql> create view view_name as select students.name sname,teachers.name from students join teachers on students.teacherid=teachers.tid; #複雜視圖的建立時要注意列頭名字不能同樣,建議用別名來建立複雜視圖
mysql> drop view view_name; #刪除視圖
觸發器:
觸發器解釋:當一個事件發生時伴隨着另外一個事件的發生,具體的伴隨事件發生狀況要根據本身定義的策略
mysql> create trigger trigger_student after insert on student_info for each row update student_count set student_count=student_count+1;
Query OK, 0 rows affected (0.01 sec)
說明:觸發器的策略定製 當在student_info中插入數據時student_count會自動增長一
mysql> select * from student_info;
Empty set (0.00 sec)
mysql> select * from student_count;
+---------------+
| student_count |
+---------------+
| 0 |
+---------------+
1 row in set (0.00 sec)
mysql> desc student_info;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| stu_id | int(11) | NO | PRI | NULL | auto_increment |
| stu_name | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> insert into student_info values(1,'zhang');
Query OK, 1 row affected (0.00 sec)
mysql> select * from student_info;
+--------+----------+
| stu_id | stu_name |
+--------+----------+
| 1 | zhang |
+--------+----------+
1 row in set (0.00 sec)
mysql> select * from student_count;
+---------------+
| student_count |
+---------------+
| 1 |
+---------------+
1 row in set (0.00 sec)
觸發器的查詢:
mysql> show triggers\G;
觸發器的刪除:
mysql> drop trigger triggername;
數據庫帳戶的增長及受權:
帳號的查詢:
mysql> select user,host,password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | localhost.localdomain | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | 127.0.0.1 | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| | localhost | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| | localhost.localdomain | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | 192.168.127.7 | *128977E278358FF80A246B5046F51043A2B1FCED |
+------+-----------------------+-------------------------------------------+
6 rows in set (0.00 sec)
說明:一個帳號是user和host一塊兒纔是一個完整的帳號,而host中的ip是客戶端的ip地址,一樣的當客戶端鏈接服務端時的ip地址是服務端的ip
帳號的刪除:
mysql> drop user root@'192.168.127.7';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host, password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | localhost.localdomain | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | 127.0.0.1 | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| | localhost | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| | localhost.localdomain | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
+------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
帳號的建立:
mysql> create user root@'192.168.127.7' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host, password from mysql.user;
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | localhost.localdomain | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | 127.0.0.1 | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| | localhost | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| | localhost.localdomain | *5D83A6402DF44A7D8EC2B8861B19F8A2F4F3EA2F |
| root | 192.168.127.7 | *128977E278358FF80A246B5046F51043A2B1FCED |
+------+-----------------------+-------------------------------------------+
6 rows in set (0.00 sec)
帳號鏈接:
[root@localhost ~]# mysql -uroot -pcentos -h 192.168.127.142
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
說明:此命令是在另外一個終端上的,非服務器端。這個ip是服務端的ip地址,此終端的ip地址爲192.168.127.7(客戶端的ip)-p中的centos是密碼
帳號的受權:
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
說明:這個是新增帳號的庫的顯示
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hellodb |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
說明: 這個是管理員鏈接同一個數據庫的庫的顯示
受權:
mysql> grant all on hellodb.* to root@'192.168.127.7';
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hellodb |
| test |
+--------------------+
3 rows in set (0.00 sec)
說明:只有管理員才能夠受權,本次受權是all(insert,select.....)庫文件是hellodb下的全部的表,固然了也能夠部分受權。
部分受權:
mysql> grant select(stuid,name) on hellodb.student to root@'192.168.127.7';
說明:受權庫某個表的select的部分權限
查看受權:
mysql> show grants for root@'192.168.127.7';
+-----------------------------------------------------------------------------------------------------------------+
| Grants for root@192.168.127.7 |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'192.168.127.7' IDENTIFIED BY PASSWORD '*128977E278358FF80A246B5046F51043A2B1FCED' |
| GRANT ALL PRIVILEGES ON `hellodb`.* TO 'root'@'192.168.127.7' |
+-----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
刪除受權:
mysql> revoke all on hellodb.* from root@'192.168.127.7';
Query OK, 0 rows affected (0.00 sec)
約束:
新增非空約束:
mysql> create table t1(id int(10) not null,name varchar(20)); #約束建立(在建表時)
mysql> insert into t1 values(null,'zhang');
ERROR 1048 (23000): Column 'id' cannot be null
mysql> alter table t1 modify name varchar(20) not null; #建表後增長約束
mysql> insert into t1 values(1,null);
Query OK, 1 row affected (0.00 sec)
mysql> alter table t1 modify name varchar(20) not null;
Query OK, 1 row affected, 1 warning (0.10 sec)
Records: 1 Duplicates: 0 Warnings: 1
mysql> insert into t1 values(1,null);
ERROR 1048 (23000): Column 'name' cannot be null
刪除約束:刪除約束就是在新增約束時不加約束條件在從新定義一遍
惟一約束:主鍵的設置
————————————————
版權聲明:本文爲CSDN博主「root_oo7」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接及本聲明。
原文連接:https://blog.csdn.net/root__oo7/article/details/82817501sql